简体   繁体   中英

How to limit product category for WooCommerce recent product slider on home page

I have a new WooCommerce (2.0.20) WordPress (3.8.1) site using the Athena (1.0.17) theme. The home page has a recent products slider. I have a product category called "articles" that I do not want to appear in the recent products slider. I think that the piece of code I need to change is

$number_of_products = $settings['shop_area_entries'];
$args = array(
    'post_type' => 'product',
    'posts_per_page' => intval( $number_of_products ),
    'meta_query' => array( array(
        'key' => '_visibility',
        'value' => array('catalog', 'visible'),
        'compare' => 'IN'
        ))
);

$first_or_last = 'first';
$loop = new WP_Query( $args );
$query_count = $loop->post_count;
$count = 0;

Can anyone tell me how I need to change the $args so that only products that are NOT of category "articles" are returned in the WP_Query?

With the help of WP_Query Woocommerce products that belong in distinct multiple categories only tax_query (not sure why I didn't find this on my first pass through previous questions!) I found that all I needed to do was change my args to:

$args = array(
'post_type' => 'product',
'product_cat' => 'books',
'posts_per_page' => intval( $number_of_products ),
'meta_query' => array( array(
    'key' => '_visibility',
    'value' => array('catalog', 'visible'),
    'compare' => 'IN'
    ))
);

And if I want to add more categories I just need to add a comma delimited list of catalog slugs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM