Skip to content

Instantly share code, notes, and snippets.

@sauraMe
Created December 4, 2017 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauraMe/5ce30b3fe3b5ca4fb1a29f217a16add1 to your computer and use it in GitHub Desktop.
Save sauraMe/5ce30b3fe3b5ca4fb1a29f217a16add1 to your computer and use it in GitHub Desktop.
Remove pages from search results using WordPress.
<?php
//* Do NOT include the opening php tag
//* Remove pages from search results
add_filter( 'pre_get_posts', 'bg_search_exclude' );
function bg_search_exclude($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment