我希望展示精选产品,但我的查询不返回任何内容! 我展示了我的一个产品,但没有显示任何东西。
<?php
$terms = array(
"post_type" => "product",
"orderby" => "date",
"order" => "DESC",
"posts_per_page" => 12,
"meta_query" => array(array('key' => '_featured','value' => 'yes'))
);
$query = new WP_Query( $terms );
while($query->have_posts()){
$query->the_post();
global $product;
?>
也谢谢
答案 0 :(得分:0)
使用短代码[featured_products per_page =“12”columns =“4”]
或自定义逻辑:
$args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 12
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
while ($featured_query->have_posts()) :
$featured_query->the_post();
$product = get_product( $featured_query->post->ID );
// Output product information here
echo "<pre>";print_r($product);echo "</pre>";
endwhile;
endif;
wp_reset_query(); // Remember to reset
参考此处:http://biostall.com/how-to-display-woocommerce-featureds-product-without-a-shortcode/