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',
) ),
);
它应该会起作用。使用WordPressget\u post()
函数测试了这个参数数组(它可以工作)
相关:@Lyall我已经使用get\u posts()
在WP\u查询上测试了这一点,它工作得很好……你说得对,它工作得很好,我只是需要在我的特定设置中解决这个问题。全部排序完毕,感谢您的快速回答:)