Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 排除';隐藏的';在WooCommerce 3+;_Php_Wordpress_Woocommerce_Custom Taxonomy_Taxonomy Terms - Fatal编程技术网

Php 排除';隐藏的';在WooCommerce 3+;

Php 排除';隐藏的';在WooCommerce 3+;,php,wordpress,woocommerce,custom-taxonomy,taxonomy-terms,Php,Wordpress,Woocommerce,Custom Taxonomy,Taxonomy Terms,我有一个旋转木马插件,它可以做各种事情,它只显示已发布的产品: $common_args = array( 'post_type' => 'product', 'posts_per_page' => !empty($posts_per_page) ? intval($posts_per_page) : 4, 'post_status' => 'publish', 'ignore_st

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

$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,

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


请告诉我如何执行这两项操作?

由于Woocommerce 3产品可见性由术语
从目录中排除
的分类法
产品可见性
处理,因此您需要添加一个税务查询,如下所示:

$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\u post()
函数测试了这个参数数组(它可以工作)



相关:

@Lyall我已经使用
get\u posts()
WP\u查询上测试了这一点,它工作得很好……你说得对,它工作得很好,我只是需要在我的特定设置中解决这个问题。全部排序完毕,感谢您的快速回答:)