Support » Themes and Templates » the_tags() does not work in WP_Query Loop. A Bug?

  • Hi,

    i have installed WP 2.5.1 and trying to view the Tags with the the_tags() function. My Code is below:

    <?php $my_query = new WP_Query('showposts=10'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <?php the_title(); ?>
    
            <div class="def"><?php the_content(); ?></div>
        	<?php the_tags(); ?>
    
    <?php endwhile; ?>

    But i does not work for me! I have tried it on multiple installation 2.5 and 2.5.1. But i didnt get it working. When i try the following:

    <?php while(have_posts()) : the_post() ?>
            <?php the_title(); ?>
    
            <div class="def"><?php the_content(); ?></div>
        	<?php the_tags(); ?>
    
    <?php endwhile; ?>

    I mean switch from new WP_Query Object to the default Loop Object it works???? Whats wrong? Is it a Bug?

    thanks
    yavuz

Viewing 4 replies - 1 through 4 (of 4 total)
  • Justin Tadlock

    (@greenshady)

    WordPress God

    I haven’t tested your code, but I why not just use the query_posts() instead?

    Do something like this:

    query_posts("showposts=10");

    I rarely run across situations where we absolutely need to use WP_Query().

    right before you “while” statement add:

    $wp_query->in_the_loop = true;

    Yes, I can verify this problem. The $wp_query->in_the_loop = true; does not solve it. Changing to query_posts is not an option for me.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    The $wp_query->in_the_loop = true; will indeed solve it, as long as you’re using the correct $wp_query object.

    global $wp_query;
    $wp_query->in_the_loop = true;
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘the_tags() does not work in WP_Query Loop. A Bug?’ is closed to new replies.