2013-07-03 75 views
0

所以这一直让我发疯。使用特定标签(wordpress)列出自定义帖子类型

我可以很容易地列出所有的文章标题是有一定的标签,就像这样:

<?php 
query_posts('tag=products'); 
if (have_posts()) while (have_posts()) : the_post(); 
echo "<h1>" . the_title() . "</h1>"; 
endwhile; 
wp_reset_query(); ?> 

但是,这只是所有标准的职位。我需要做的,而不是如果只为一定的自定义帖子类型(我的自定义帖子类型被称为'产品')工作。换句话说,它应该显示标签为'webonly'的所有'产品'自定义帖子类型的标题。

任何建议将有所帮助。

回答

2

显示信息的所有名单这在附加webonly标记

notice-tag = your tag taxonomy name 

terms in define your tag slug name 

'post_type'=>'notice', in define your post type 
<?php 
    $args = array(
      'tax_query' => array(
         array(
          'taxonomy' => 'notice-tag', 
          'field' => 'slug', 
          'terms' => array('webonly') 
         ) 
       ), 
      'post_type'=>'notice', 
      'order'=>'ASC', 
      'posts_per_page'=>-1 
    ); 
    query_posts($args); ?> 
    <?php while (have_posts()) : the_post(); ?> 

    <?php echo the_title(); ?> 

    <?php endwhile; ?> 
+0

宾果。只需在最后重置查询,现在都很好。谢谢一堆! – Miker

相关问题