我已经查看了这个问题和这个问题,但我仍然无法解决。
第一版导致没有相关的产品显示,因此它破坏了代码。第二版没有影响。
我该如何解决这个问题?
谢谢
我有一个名为"status"
的属性,我只想要值为"OPEN"
的类别(产品)出现。我正在编辑related.php WooCommerce模板文件。
以下是我尝试过的两个版本的代码。
版本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 );
第一版导致没有相关的产品显示,因此它破坏了代码。第二版没有影响。
我该如何解决这个问题?
谢谢