小编use*_*629的帖子

WooCommerce通过属性查询获取产品

我有一个属性颜色的产品.属性值为红色,蓝色和绿色.我正在尝试创建自定义搜索,但我无法获取查询以提取任何产品.

$args =  array(
    'post_type'      => array('product'),
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'meta_query'     => array( 
        array(
            'key' => '_visibility',
            'value' => array('catalog', 'visible'),
            'compare' => 'IN',  
        ) 
    ),
    'tax_query'      => array( 
        array(
            'taxonomy'        => 'product',
            'field'           => 'slug',
            'terms'           =>  array('blue', 'red', 'green'),
            'operator'        => 'IN',
        ),
    )
);

$products = new WP_Query( $args );
Run Code Online (Sandbox Code Playgroud)

我哪里做错了?

php wordpress attributes product woocommerce

6
推荐指数
1
解决办法
9907
查看次数

标签 统计

attributes ×1

php ×1

product ×1

woocommerce ×1

wordpress ×1