WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the following to bring up a tag archive page:

<?php query_posts( "tag=". '' . single_tag_title( '', false ) . '' ); ?>

This works perfectly for all tags of one word only, but any tags of more than one word (eg: "tag one", slug: "tag-one") do not display.

Is it possible to query_posts by tag slug, rather than single_tag_title?


share|improve this question
up vote 6 down vote accepted

The single_tag_title() function returns the tag title while you need the tag slug or ID for use in query_posts(). This should get you started:

if ( is_tag() ) {
    $tag       = get_queried_object();
    $tag_title = $tag->name; // Same as single_tag_title()
    $tag_slug  = $tag->slug;
    $tag_id    = $tag->term_id;


share|improve this answer
That's perfect, thanks!! :D – KingLiNoodles Jun 8 '12 at 10:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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