Skip to content

Instantly share code, notes, and snippets.

@sjaved87
Created June 19, 2016 13:19
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 sjaved87/024e7db1946160be6472c5a0d17492f6 to your computer and use it in GitHub Desktop.
Save sjaved87/024e7db1946160be6472c5a0d17492f6 to your computer and use it in GitHub Desktop.
Include only specific post types in search results. The following will only include post and product post types in search results. Feel free to add remove your own post type names (coma separeated)
<?php
function SearchFilter( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'product' ) );
}
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment