Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks!

share|improve this question

1 Answer 1

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;
}

http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

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

Your Answer

 
discard

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.