How do I use "new WP_Query()" within a plugin? (2 posts)

  1. Jeff
    Posted 7 years ago #

    I'm wanting to start a new loop within a plugin (to be brief) and I've tried using $new_query = new WP_Query but I find that the result array I am getting is empty of values (I've checked it with print_r() and found that only the keys are there).

    Is what I am wanting to do possible? And if so am I missing a global variable of some sort?

  2. tomgf
    Posted 7 years ago #

    I found a similar problem writing a widget plugin.

    I was using this structrure:

    <?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; ?>
    <!-- Do stuff... -->
    <?php endwhile; ?>

    I found out that the proper values (the ones that you want to call in the Do stuff space) are not in $post but in $my_query->post. Maybe was it also your case?

Topic Closed

This topic has been closed to new replies.

About this Topic