web-dev-qa-db-ja.com

Have_postsで無限ループに陥るのはなぜですか?

次のようなコードがあります。これは何らかの理由で無限ループを引き起こします。何が起こっているのか説明できますか?

ありがとうございます。

<?php 

$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">
                <tr>
                    <th>Store</th>
                    <th>Flag Reason</th>
                    <th>Delete Flag</th>
                </tr>
                <?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;?>
            </table>
    <?php else: ?>
            No flags found.
    <?php endif; ?>
2
yuval

この答えを見てください。 タグでカスタム投稿タイプを取得します

私はあなたがwhileループの中で$flagged_stores->the_post()を使うことを信じる。

3
brownian
1
Michael

これが無限ループの原因となっているのかどうかはわかりませんが、WP_Queryはオフになっています。

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

'orderby''posts_per_page'を更新しました。

0
Evan Yeung