Skip to content

Instantly share code, notes, and snippets.

@shrwnsan
Created April 13, 2013 04:23
Show Gist options
  • Select an option

  • Save shrwnsan/5376927 to your computer and use it in GitHub Desktop.

Select an option

Save shrwnsan/5376927 to your computer and use it in GitHub Desktop.
WordPress: exclude custom post-types from search query results. Note: 'video-camera', 'software-solution','post' are the post types which you want to search replace with you own. Source: http://wordpress.org/support/topic/exclude-custom-post-types-from-search-query-results?replies=6#post-3249786
// search filter
function fb_search_filter($query) {
if ( !$query->is_admin && $query->is_search) {
$query->set('post_type', array('video-camera', 'software-solution','post') ); // id of page or post
}
return $query;
}
add_filter( 'pre_get_posts', 'fb_search_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment