在Wordpress中通过标签获取帖子

时间:2015-05-11 10:52:32

标签: wordpress tags

我希望在我的主页模板中使用特定标签获取帖子" iinluv" 我写了查询代码但失败了。 这是我的代码。

<ul class="team-list">
<?php   $args = array( 'post_type' => 'product', 'tag' => 'iinluv', 'posts_per_page' => -1, );

$loop = new WP_Query( $args );    while ( $loop->have_posts() ) : $loop->the_post(); global $product;   $title = get_the_title();   $ptitle = $title;?>



<!-- TEAM THUMB -->
<li class="team-block bg-alt">
        <?php echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog imageproduct'); ?>

</li>
<!-- TEAM THUMB -->
<?php endwhile;?>

            </ul>

请检查我的代码,并给我一个很好的建议来完成它。

1 个答案:

答案 0 :(得分:0)

假设您使用WooCommerce,因为您已将product指定为post_type。要获取某些代码或类别的帖子,您必须使用tax_query。检查以下示例。

$args = array(
  'post_type' => 'product',
  'posts_per_page' => -1,
  'tax_query' => array(
      array(
        'taxonomy' => 'product_tag',
        'field'    => 'slug',
        'terms'    => 'iinluv',
      ),
    ),
  );