Created
March 15, 2021 10:01
-
-
Save wplit/949eab4991e69257abd7c17ab5d89fcd to your computer and use it in GitHub Desktop.
limit search results to only show products
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
/* Filter search query to only display products */ | |
add_filter('pre_get_posts','lit_search_products_only'); | |
function lit_search_products_only($query) { | |
if ($query->is_search && !is_admin() ) { | |
$query->set('post_type',array('product')); | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment