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 have the following code, which causes an infinite loop for some reason. Can anybody explain what's going on please?



$flagged_stores = new WP_Query( array ( 'post_type' => 'store', 'orderby' => 'post_id', 'meta_key' => 'flagged', 'limit' => 10 ) );

   if($flagged_stores->have_posts()): ?> 
        <div class="table">
            <table class="form-table">
                    <th>Flag Reason</th>
                    <th>Delete Flag</th>
                <?php while($flagged_stores->have_posts()): ?>
                    <td><?php echo the_title(); ?></td>
                    <td><?php// echo get_post_custom_values('flagged'); ?></td>
                    <td><?php// echo "Delete"; ?></td>
                <?php endwhile;?>
    <?php else: ?>
            No flags found.
    <?php endif; ?>
share|improve this question

3 Answers 3

Look at this answer: get custom post type by tag

I believe you'd use $flagged_stores->the_post() inside while loop.

share|improve this answer
+1 - well spotted; it should indeed read: <?php while($flagged_stores->have_posts()): $flagged_stores->the_post(); ?> - @yuval: did the endless loop always show the same title? –  Michael Nov 20 '11 at 21:50
@Michael yes, because you don't seek post by post without the_post() –  brownian Nov 21 '11 at 7:29

try and use 'posts_per_page' instead of 'limit' - http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

share|improve this answer
Still no luck. Any other ideas? Thanks! –  yuval Nov 20 '11 at 17:52

I do not know if this is what caused the infinite loop, but your WP_Query is off.

$flagged_stores = new WP_Query( array ( 'post_type' => 'store', 'orderby' => 'ID', 'meta_key' => 'flagged', 'posts_per_page' => 10 ) );

I updated 'orderby' and 'posts_per_page'.

share|improve this answer
No luck. Tried it and the loop itself is still an infinite one... –  yuval Nov 20 '11 at 17:52

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.