Skip to content

Instantly share code, notes, and snippets.

@wplit
Created March 15, 2021 10:01
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 wplit/949eab4991e69257abd7c17ab5d89fcd to your computer and use it in GitHub Desktop.
Save wplit/949eab4991e69257abd7c17ab5d89fcd to your computer and use it in GitHub Desktop.
limit search results to only show products
/* 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