WordPress Bug: Tags do not appear under WP_Query

WordPress has been perfect and bug-free for me. However, I discovered one lately. Firstly I came across this bug when I was developing an Gawker-style WordPress theme for a client of mine. I used custom WP_Query loops several times there and I was asked to display tags inside them too, the way Gawker does. This did not happen, of course, that is why I am writing this post. By that time I thought it was my fault that tags did not appear.

A couple of weeks ago, I coded a new theme for my blog. I used several custom loops there too, powered by the famous WP_Query. When I tried again to show the tags inside them, they did not show up. That made assured me that it was a bug. To have more context about this, please have a look at the following WordPress loop:

{code type=php}

<?php $my_query = new WP_Query(‘category_name=featured&showposts=1′);
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[$post->ID] = $post->ID; ?>

<div class=”featured_post” id=”post-<?php the_ID(); ?>”>

<img src=”<?php echo get_post_meta($post->ID, ‘Featured_Image’, true) ?>” alt=”" id=”featured_img” />

<h3 class=”title”><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a>  </h3>

<div class=”meta”>By <strong><?php the_author();?></strong> &raquo;

<?php comments_popup_link(’0 comments’, ’1  comment’, ‘% comments’); ?>

<?php the_tags(); ?>

</div>

<?php the_excerpt() ?>

</div>

<?php endwhile; ?>

{/code}

As you can see, the tags code is included in the loop, but nothing appears. This does not work only under the WP_Query powered loops, whereas in a normal loop, it works. I would appreciate very much that everybody contributes to make this bug known to the WordPress team as soon as possible so that they can have it fixed. Thanks very much!

6 thoughts on “WordPress Bug: Tags do not appear under WP_Query

  1. I solved this way:

    while ($the_query->have_posts())
    {
    $the_query->the_post();
    $do_not_duplicate[$the_query->post->ID] = $the_query->post->ID;
    $tags = wp_get_post_tags($the_query->post->ID);
    foreach($tags as $key => $value)
    {
    $menu .= ‘‘.$value->name.’‘;
    }
    }
    $menu .= ‘
    ‘ . chr(13);
    }

  2. Sorry, this way:

    while ($the_query->have_posts())
    {
    $the_query->the_post();
    $do_not_duplicate[$post->ID] = $post->ID;
    $tags = get_the_tags($the_query->post->ID);
    foreach($tags as $key => $value)
    {
    $menu .= ‘‘.$value->name.’‘;
    }
    }
    $menu .= ‘
    ‘ . chr(13);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *