This topic has 2 replies, 2 voices, and was last updated 8 years, 4 months ago ago by Brian Johnson
Hello,
i need to filter the results of product text search to be limited to the products that are in a specific category!
I already did something really similar, to display everywhere in my site only products that have a specific category.
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
//if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && ( is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy() || is_filtered() || is_search() ) ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'web' ), // Display only products in the "web" category on the shop page
'operator' => 'IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
Now i need something similar to work both on the search result archive page, (i added is_search() but turns out it only works for normal wordpress search result pages), and for the ajax search too…
Even if you can only point me in the right direction i would appreciate.
Thank You.
Hello
Sorry . The modification you asked to do requires additional customization which lays beyond the scope of our basic support.
Regards,
Brian Johnson
You must be logged in to reply to this topic.Log in/Sign up