I'm having problems getting all related posts of the current viewing tag. Does anyone know how you can do this dynamic? I want to create a own kind of 'archive' page for this.

3 Answers 3


Ok .. after searching for a while I figured out what I was doing wrong. I wasn't including custom post types in the loop. I ended up constantly with 'not found'.

Whats the solution:

query_posts( array( 'post_type' => 'blog', 'showposts' => 3, 'orderby' => 'rand') );  if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

And it queues all posts with the current viewing tag!

Special thanks to Sven and Kaiser!


Simply use a tag archive for that.

You can grab a term/taxon, then display a link to its archive using get_tag_link().

As you can see from the Template Hierarchy Diagram, there're the following tempalte names, that will trigger (in hierarchical & parent/child theme) order:

  • tag-{$slug}.php
  • tag-{$id}.php
  • tag.php
  • archive.php

There you will have - depending on your URl/Route - the posts available and can proceed them using a plain loop, like the one you can see in the codex. All filters are available, as well as well as all filters like pre_get_posts, etc. and Conditional Tags like is_tag() that will determine if you're on a tag archive.


You can use the default get_posts() function from WordPress with taxonomy parameter.

  • Thanks Sven, but how do I get the posts related to the current tag? I've managed to output the single_tag_title(); but don't know how to get the rest..
    – rwzdoorn
    Commented Dec 11, 2012 at 10:31
  • So, you need the tag of the current post? You can get the tags with the function get_the_tags() (codex.wordpress.org/Function_Reference/get_the_tags)
    – Sven
    Commented Dec 11, 2012 at 10:34
  • 1
    Nope sven, This is what I did: When viewing a post, I click on one of the tags (like Android), i'm going to the tag.php page and want to display all related posts with the tag 'Android'..
    – rwzdoorn
    Commented Dec 11, 2012 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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