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 have the following code which SHOULD print out the title of all posts with the associated tag (in this case the tag is 'icon'):

    $tagname = get_query_var('tag');

    if( is_tag()  ){
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( array('post_type'=>array( 'photo', 'post'),'paged'=>$paged, 'tag'=>$tagname ) );

<?php while ( have_posts() ) : the_post(); ?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="item">      

<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

</div><!-- #post-## -->

<?php endwhile; // End the loop. Whew. ?>

    <?php wp_reset_query(); ?>

I can confirm that $tagname contains the value of 'icon' when echoed. The problem is, no posts are being returned when I know there are 8 posts with the tag 'icon'!

Why is that?

share|improve this question

closed as too localized by toscho May 30 '12 at 22:18

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Does the is_tag() return true? –  Wyck May 23 '12 at 5:59
it returns the value 1 –  Sweepster May 23 '12 at 14:44
Why is this question tagged with custom-post-types? Is that tag relevant to this question? –  Chip Bennett May 29 '12 at 19:51
Because the code is querying custom post types: query_posts( array('post_type'=>array( 'photo', 'post') and it could possibly be the root of the problem? –  Sweepster May 29 '12 at 21:36

1 Answer 1

The is_tag() conditional tag returns true if fed an existing tag slug or an array of existing tag slugs.

If used without an argument, as you currently are doing, it returns true when on a tag archive page.

I am assuming your above custom loop is not an archive page?! If so, is_tag() returns false and your query isn't run.

Also note that, if this is a secondary loop/query, you should use the WP_Query class instead. Read why.

share|improve this answer
It is indeed a tag archive page and returns value 1. –  Sweepster May 23 '12 at 14:45

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