WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've taken a very minimalistic loop, and tried to modify it, so that I can use more then one loop on one page.

The minimalistic loop works fine and gets the content. But my modification to allow it to be re-used fails.

This is the working loop:


if (have_posts()) : 


<?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?> 
<?php endwhile; ?>

All good so far. That actually works. But if I want to have more then one loop on a page, I'm forced to work with WP_Query.

So, I modify my loop thus:


$my_query = new WP_Query() ;

if ($my_query->have_posts()) : 


<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php $my_query->the_content(); ?> 
<?php endwhile; ?>

But now I get nothing back at all. I don't get any errors, and php after that loop continues to execute. But I'm not getting any content.

Where am I going wrong? How do I actually get the content?

share|improve this question

You have to pass some arguments to new WP_Query or no database request will be sent. Your check …

if ($my_query->have_posts())

… will never evaluate to TRUE, because there are no data.

share|improve this answer
thanks. So now I'm stuck on which parameter to use. I just need the most minimal parameter set possible, in order to just get the actual content of the Page. I've been looking at the docs for WP_Query, but I can't figure this out. Any idea what my args should be? – bob Jan 18 '13 at 3:33
@bob The content of the page is in $GLOBALS['post']. – toscho Jan 18 '13 at 5:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.