Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?php

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:

<?php

$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

1 Answer 1

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

 
discard

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.