Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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