简体   繁体   English

如何限制主页上WooCommerce最近产品滑块的产品类别

[英]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. 我有一个使用Athena(1.0.17)主题的新WooCommerce(2.0.20)WordPress(3.8.1)网站。 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. 我有一个产品类别“ articles”,我不想出现在“最新产品”滑块中。 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? 谁能告诉我我该如何更改$ args,以便在WP_Query中仅返回不属于“ articles”类别的产品?

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: 借助WP_Query Woocommerce产品的帮助, 这些产品属于不同的多个类别,仅tax_query (不确定为什么我在第一次通过前面的问题时没有找到它!)我发现我需要做的就是将我的参数更改为:

$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. 而且,如果我想添加更多类别,我只需要添加一个以逗号分隔的目录条目列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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