Php 按属性筛选的商业相关产品

Php 按属性筛选的商业相关产品,php,wordpress,woocommerce,attributes,product,Php,Wordpress,Woocommerce,Attributes,Product,我已经看过了,但我还是被卡住了 我有一个属性“status”,我只希望显示值为“OPEN”的类(产品)。我正在编辑相关的.php.com模板文件 下面是我尝试过的两个版本的代码 第1版: $args = apply_filters( 'woocommerce_related_products_args', array( 'post_type' => 'product', 'ignore_sticky_posts' => 1, 'no_found_rows'

我已经看过了,但我还是被卡住了

我有一个属性
“status”
,我只希望显示值为
“OPEN”
的类(产品)。我正在编辑相关的.php.com模板文件

下面是我尝试过的两个版本的代码

第1版:

 $args = apply_filters( 'woocommerce_related_products_args', array(
'post_type'            => 'product',
'ignore_sticky_posts'  => 1,
'no_found_rows'        => 1,
'posts_per_page'       => $posts_per_page,
'orderby'              => $orderby,
'post__in'             => $related,
'post__not_in'         => array( $product->id ),
'meta_query' => array(
   array(
    'key' => 'status',
    'value' => 'OPEN',
   ),
 ),
 ) );
第2版:

    $key="status";
    $value="OPEN";
    $query_status = array('meta_key' => $key, 'meta_value' => $value);
    $meta_query[] = $query_status;

    $args = apply_filters( 'woocommerce_related_products_args', array(
    'post_type'            => 'product',
    'ignore_sticky_posts'  => 1,
    'no_found_rows'        => 1,
    'posts_per_page'       => $posts_per_page,
    'orderby'              => $orderby,
    'post__in'             => $related,
    'post__not_in'         => array( $product->id ),
    'meta_query'           => $meta_query,
     ) );

    $products                    = new WP_Query( $args );
第一个版本导致没有相关产品显示,因此它破坏了代码。第二种方法没有效果

我如何解决这个问题


谢谢

好的,我有答案了!WooCommerce以多种方式存储自定义属性,但在本例中,我需要使用术语查询而不是元查询。这是最后一个问题,它就像一个符咒:

$args = apply_filters( 'woocommerce_related_products_args', array(
       'post_type'            => 'product',
       'ignore_sticky_posts'  => 1,
       'no_found_rows'        => 1,
       'posts_per_page'       => 4,
       'orderby'              => $orderby,
       'post__not_in'         => array( $product->id ),
       'tax_query'      =>     array(
              array(
                      'taxonomy' => 'pa_status',
                      'field' =>      'slug',
                      'terms' => 'open'
              )
        )
) );

嗯,我想我在这里写了一个回复。。。我测试了代码,但没有得到任何结果,即使我删除了'post\uu in'=>$相关参数。我想我会继续努力的。