Skip to content

Instantly share code, notes, and snippets.

@jmsmrgn
Created January 24, 2016 00:45
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 jmsmrgn/1e2b73d8d306698e41e8 to your computer and use it in GitHub Desktop.
Save jmsmrgn/1e2b73d8d306698e41e8 to your computer and use it in GitHub Desktop.
WP - Only return posts in search
/**
* Search should only return posts
*/
function search_filter($query) {
if (!$query->is_admin && $query->is_search) {
$query->set('post_type', 'post');
// $query->set('post__not_in', array(1,5,10));
}
return $query;
}
}
add_filter('pre_get_posts', 'search_filter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment