WordPress.org

Forums

the_tags() does not work in WP_Query Loop. A Bug? (5 posts)

  1. yonthebeach
    Member
    Posted 7 years ago #

    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

  2. Justin Tadlock
    WordPress God
    Posted 7 years ago #

    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().

  3. wpcast
    Member
    Posted 7 years ago #

    right before you "while" statement add:

    $wp_query->in_the_loop = true;

  4. habr@levandehistoria.se
    Member
    Posted 7 years ago #

    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.

  5. 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;

Topic Closed

This topic has been closed to new replies.

About this Topic