【问题标题】:Exclude 'hidden' queried products from carousel in WooCommerce 3+从 WooCommerce 3+ 中的轮播中排除“隐藏”查询的产品
【发布时间】:2019-09-15 04:58:05
【问题描述】:

我有一个轮播插件,它可以做各种事情,它只显示已发布的产品:

$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】:

    从 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

    【讨论】:

    • @Lyall 我已经在WP_Query 上使用get_posts() 进行了测试,它运行良好……
    • 你说得对,它工作得很好,我只需要在我的特定设置中解决问题。所有排序,感谢您的快速回答:)
    猜你喜欢
    • 2018-12-17
    • 2013-07-25
    • 2021-09-21
    • 2019-04-03
    • 2019-08-05
    • 2021-11-21
    • 2019-07-15
    • 1970-01-01
    • 2014-08-20
    相关资源
    最近更新 更多