Created
June 19, 2016 13:19
-
-
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)
This file contains 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
<?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