Skip to content

Instantly share code, notes, and snippets.

@antoniofrignani
Created June 4, 2012 09:49
Show Gist options
  • Save antoniofrignani/2867532 to your computer and use it in GitHub Desktop.
Save antoniofrignani/2867532 to your computer and use it in GitHub Desktop.
[WP] - Filter search results by post type
// http://wpsnipp.com/index.php/functions-php/filter-search-results-by-post-type/
function search_posts_filter( $query ){
if ($query->is_search){
$query->set('post_type',array('post','custom_post_type1', 'custom_post_type2'));
}
return $query;
}
add_filter('pre_get_posts','search_posts_filter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment