Hi,
I am using products slider.
Is it possible to display only featured products?
Shalom!
Can you please add a new product category and choose to display only those products on your product slider?
Cheers!
Yigit
Hi,
It may be a good idea but then I will have another category in my shop page.
If I can hide this category from shop page it can be useful.
Hi!
Yes, you can hide. Please post the link to your website after adding a new category (and point it out please) and we will help you hide it
Cheers!
Yigit
Here it is.
Can you please post the explanation how did you do it?
Hey!
Please add following code to Functions.php file in Appearance > Editor
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() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'knives' ), // Don't display products in the knives category on the shop page
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
Regards,
Yigit
I added the code. I still see the category.
Should I update something in it?
Hi!
Yes, sorry forgot to mention it in the previous post. “knives” in the code is the category that will be hidden. Please replace “knives” with your category name
Cheers!
Yigit
I did it, but it is not working.
I tried name or slug.