WordPress Bug: Tags do not appear under WP_Query

By BANAGO » Code » November 8th, 2008

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:

<?php $my_query = new WP_Query('category_name=featured&amp;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> »
<?php comments_popup_link('0 comments', '1  comment', '% comments'); ?>
<?php the_tags(); ?>
</div>
<?php the_excerpt() ?>
</div>
<?php endwhile; ?>

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 people shared their opinion »

  1. daweb

    March 6, 2009
    at 2:29 pm

    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. daweb

    March 6, 2009
    at 2:32 pm

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

  3. BANAGO

    March 6, 2009
    at 6:36 pm

    Thanks very much – I will try that out and I’ll let you know. Thanks once more!

  4. daweb

    March 6, 2009
    at 6:43 pm

    You are welcome.

  5. ice machines

    April 15, 2009
    at 2:39 am

    Thanks a lot for the code!

  6. Veiniaglonger

    April 23, 2009
    at 9:03 am

    This site is very cool throughout the Internet.

Leave a comment

Copyright © 2007 - 2009 Baki Goxhaj Powered by WordPress and WPlancer