Display a specific category of products in shop page and disable code for specific actions

Question

I want to display a specific category of products on the top page of the shop page.
This was achieved with the code below.
However, with this code, when searching for products from the search console, only products in the specified category will be searched.
Is it possible to write code that invalidates the code triggered by the search console search action?

add_action('pre_get_posts','shop_filter_cat');

function shop_filter_cat($query) {
if (!is_admin() && is_post_type_archive( 'product' ) && $query->is_main_query()) {
$query->set('tax_query', array(
array ('taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( '#','#'), //
)
)
); 
}
}
0
, LMDM 3 years 2020-03-29T20:52:58-05:00 0 Answers 105 views 0

Leave an answer

Browse
Browse