2013-10-01 82 views
0

我想加载我创建的gallery_Category分类标准中猫5的帖子的所有图像。没有任何工作,我不明白为什么不。WordPress的从自定义分类标准检索帖子

<?php 

      $args = array(
        'post_type' => 'post', 
        'taxonomy' => 'gallery_category', 
        'term_id' => '5' 
      ); 
      $query = new WP_Query($args); 
      while ($wp_query->have_posts()) { 
       $wp_query->the_post(); 
       ?> 
       <?php the_post_thumbnail(); ?> 
     <?php } ?> 

回答

1
<?php 

$args = array(
    'post_type' => 'post', 
    'tax_query' => array(
     array(
      'taxonomy' => 'gallery_category', 
      'field'  => 'slug', 
      'terms'  => '5' 
     ) 
    ) 
); 

$my_query = new WP_Query($args); 
while ($my_query->have_posts()) { 
$my_query->the_post(); 

    if (has_post_thumbnail()) { 
    the_post_thumbnail(); 
    } 

} 
?> 

试试这个

也可做参考这里

wp query

wordpress loop

相关问题