2012-08-07 221 views
2

我试图在WP循环内显示帖子,并且能够成功地使用<?php query_posts('tag_id=10'); ?>这里的循环显示标签ID为10的所有帖子,但我'd也喜欢使用相同标记来显示来自“自定义帖子”类型的帖子。Wordpress循环 - 通过不同帖子类型的标签显示帖子

我能够使用<?php query_posts('tag_id=10&post_type=videos'); ?>

但我怎么能合并这两个成功显示与TAG_ID = 10个职位,从一个自定义后类型起源的?

我给了这个镜头:<?php query_posts('tag_id=10, tag_id=10&post_type=videos'); ?> 但这没有效果。

对此有何意见?

回答

2

您可以使用此

query_posts( 
    array(
     'post_type' => array('post', 'videos'), 
     'tag_id' => 10 
)); 
while (have_posts()) : the_post(); 
    // loop code 
endwhile; 
wp_reset_query(); 
+0

非常感谢谢赫! :) – danielmeade 2012-08-07 22:42:47

+0

欢迎您:-) – 2012-08-07 22:44:58

+0

从不使用'query_posts',这对性能来说是非常糟糕的。 – Foxinni 2012-08-24 13:00:38

1

这将运行一个动作之前的职位实际上查询,从而改变原来的输出您的特定需求。

function tag_archive_mod($query) { 

    if (is_tag() && $query->is_main_query()){ 

     $query->set('post_type',array('post','video')); 

    } 
} 
add_action('pre_get_posts', 'tag_archive_mod'); 

非常,是非常有用的。 http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

相关问题