Php 从WP_查询中排除没有评论的WooCommerce产品
我试图在WooCommerce网站上使用自定义查询,根据总销售额列出10种流行产品。但是,必须将没有/没有评论的同一时间产品从列表中排除。有什么方法可以做到这一点 代码如下:Php 从WP_查询中排除没有评论的WooCommerce产品,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我试图在WooCommerce网站上使用自定义查询,根据总销售额列出10种流行产品。但是,必须将没有/没有评论的同一时间产品从列表中排除。有什么方法可以做到这一点 代码如下: <?php global $woocommerce; global $product; $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'meta_key' =>
<?php
global $woocommerce;
global $product;
$args = array(
'post_type' => 'product',
'posts_per_page' => 10,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num'
);
$popular_products = new WP_Query($args);
if($popular_products->have_posts()):
?>
<ul>
<?php
while ($popular_products->have_posts()) : $popular_products->the_post();
$product = wc_get_product( get_the_ID() );
$rating = round($product->get_average_rating());
?>
<li>
<h3><?php the_title(); ?></h3>
<div><?php the_post_thumbnail(); ?></div>
<p><strong>Rating: </strong><?php echo $rating; ?>/5</p>
<a href="<?php the_permalink(); ?>">View Product</a>
</li>
<?php
endwhile;
wp_reset_postdata();
?>
</ul>
<?php endif; ?>
-
评级:/5
我开始了解“post_u_unot_uin”,但不知道如何将其用于产品评级。任何帮助都将不胜感激。以下内容将额外排除零/无评论的产品:
<?php
$products = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 10,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'meta_query' => array( array(
'key' => '_wc_review_count',
'value' => '0',
'compare' => '>',
)),
));
if( $products->have_posts() ):
?>
<ul>
<?php
while ( $products->have_posts() ) : $products->the_post();
$_product = wc_get_product( get_the_ID() );
$rating = round( $_product->get_average_rating() );
?>
<li>
<h3><?php the_title(); ?></h3>
<div><?php the_post_thumbnail(); ?></div>
<p><strong>Rating: </strong><?php echo $rating; ?>/5</p>
<a href="<?php the_permalink(); ?>">View Product</a>
</li>
<?php
endwhile;
wp_reset_postdata();
?>
</ul>
<?php endif; ?>
-
评级:/5
请注意,global$woodcommerce代码>和全球$product代码>是不需要的