【发布时间】:2018-07-31 02:15:51
【问题描述】:
我想在网站的标题中获得 3 个特色产品。但我的查询不断返回无限数量的结果。
我一直在网上寻找解决方案,并遇到了所有答案都在查询方面说相同内容的答案。我可能做错了什么?
$meta_query = WC()->query->get_meta_query();
$tax_query = WC()->query->get_tax_query();
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN',
);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 2,
'meta_query' => $meta_query,
'tax_query' => $tax_query,
);
$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 );
echo $product->title; echo "test";
// Product info here
endwhile;
}
wp_reset_query();
以下查询返回 20 个结果。代码放在 header.php 中。使用 woocommerce 3.x。
【问题讨论】:
标签: php wordpress woocommerce product custom-taxonomy