在WooCommerce 3+中排除来自旋转木马的“隐藏”查询产品

问题描述 投票:4回答:1

我有一个carousel插件,可以执行各种操作,它只显示已发布的产品:

$common_args = array(
            'post_type' => 'product',
            'posts_per_page' => !empty($posts_per_page) ? intval($posts_per_page) : 4,
            'post_status' => 'publish',
            'ignore_sticky_posts' => true,
            'no_found_rows' => true,

        );

但我需要它来排除“隐藏”的产品,这些产品在技术上仍然只是不可见。或者,如果它排除了特定类别的产品(我的所有隐藏产品都属于两个特定类别),我可以使用它。

我该怎么办?

php wordpress woocommerce custom-taxonomy taxonomy-terms
1个回答
4
投票

自Woocommerce 3以来,产品可见性由product_visibility术语exclude-from-catalog分类处理,因此您需要添加以下税务查询:

$common_args = array(
    'post_type'           => 'product',
    'posts_per_page'      => !empty($posts_per_page) ? intval($posts_per_page) : 4,
    'post_status'         => 'publish',
    'ignore_sticky_posts' => true,
    'no_found_rows'       => true,
    'tax_query'           => array( array(
        'taxonomy'  => 'product_visibility',
        'terms'     => array('exclude-from-catalog'),
        'field'     => 'name',
        'operator'  => 'NOT IN',
    ) ),
);

它应该工作。用WordPress get_post()函数测试了这个参数数组(它的工作原理)。


相关:Database changes for products in woocommerce 3

© www.soinside.com 2019 - 2024. All rights reserved.