Code

WordPress Bug: Tags do not appear under WP_Query

0

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!

Baki Goxhaj
I’m a web consultant specializing in WordPress. I love elegant solutions, quality code and a good laughter.
You may also like
I’m Sad to See WordPress Themes Using Tables
recent-comments
Without a Plugin: Display Recent Comments
6 Comments
  • Veiniaglonger Apr 23,2009 at 9:03 am

    This site is very cool throughout the Internet.

  • ice machines Apr 15,2009 at 2:39 am

    Thanks a lot for the code!

  • daweb Mar 6,2009 at 6:43 pm

    You are welcome.

  • BANAGO Mar 6,2009 at 6:36 pm

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

  • daweb Mar 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);
    }

  • daweb Mar 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);
    }

Leave Your Comment

Your Comment*

Your Name*
Your Webpage