Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide pages from search results
<?php
add_filter('pre_get_posts','your_custom_search_filter');
function your_custom_search_filter($query) {
if (!is_admin() && $query->is_search) {
$exclude_ids = array(1,2,3); //page ids you want to exclude
$query->set('post__not_in', $exclude_ids);
}
return $query;
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment