我有一个类别列表:最佳产品>产品列表。我写这个查询,以获得所有最好的产品,如果用户检查到最好的产品。我使所有的产品只是检查在产品列表,但我的主页仍然显示他们所有。这是怎么了?谢谢你的代表:)
<div class="col-xs-12 clear products">
<div class="col-xs-12 clear responsive-bp">
<?php
$args = array(
'post_type' => array('products'),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'products-category',
'field' => 'slug',
'terms' => array('best-products'),
'operator' => 'IN',
),
),
'posts_per_page' => 6,
);
// WP_Query
$eq_query = new WP_Query( $args );
if ($eq_query->have_posts()) : // The Loop
?>
<?php
while ($eq_query->have_posts()): $eq_query->the_post();
?>
<div class="item-np col-xs-12">
<a class="fl pro-img" title="<?php the_title();?>" href="<?php the_permalink();?>"><span class="marked-img"></span><?php if ( has_post_thumbnail() ) {the_post_thumbnail('medium');}?></a>
<a class="clear col-xs-12 pro-tit" title="<?php the_title();?>" href="<?php the_permalink();?>"><?php the_title() ;?></a>
<span class="clear col-xs-12 pro-type"><a href="<?php the_permalink();?>">View</a></span>
<p class="clear col-xs-12 pro-price">
<span><?php echo get_post_meta( $post->ID, 'wpcf-product-price', true ); ?></span> <span><?php echo get_post_meta( $post->ID, 'weight-product', true ); ?></span>
</p>
</div>
<?php endwhile; wp_reset_query(); ?>
<?php endif; ?>
</div>
</div>
我认为这段代码应该适合你:
$args = array(
'post_type' => array('products'),
'tax_query' => array(
array(
'taxonomy' => 'products-category',
'field' => 'slug',
'terms' => 'best-products',
),
),
'posts_per_page' => 6,
);