I'm trying to display posts within the WP loop and am able to successfully do so with <?php query_posts('tag_id=10'); ?> Here the loop will display all posts with the tag ID of 10, but I'd also like the loop to display posts from within a Custom Post type by the same tag.

I'm able to successfully display posts with tag_id=10 that originate from a custom post type using <?php query_posts('tag_id=10&post_type=videos'); ?>

But how can I merge the two?

I gave this a shot: <?php query_posts('tag_id=10', 'tag_id=10&post_type=videos'); ?> but that had no effect (well actually it broke everything!)


may i suggest you use instead get_posts()?


$args_t10 = array(
  'tag_id' => 10,
$postslist_t10 = get_posts( $args_t10 ); ?>

$args_t10_v = array(
   'tag_id' => 10,
   'post_type' => 'videos'
$postslist_t10_v = get_posts( $args_t10_v );

you then can merge and filter the duplicates

$postmixed = array_merge($postslist_t10, $postslist_t10_v);
$uniqueposts = array_unique(postmixed);


wp: get_posts() and parameters

php: array-unique() , array_merge

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.