Created
January 24, 2016 00:45
-
-
Save jmsmrgn/1e2b73d8d306698e41e8 to your computer and use it in GitHub Desktop.
WP - Only return posts in search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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