私は問題を説明する情報を見回しましたが、何も見つかりませんでした。私は、おそらくすべての子供カテゴリーの「人員」を列挙するループを持っています。何らかの理由でループが無限に再開します。私はチェックして、foreachとwhileループの両方から出ますが、引き続きループを維持しています。何か案は?ここで、query_postsが無限ループを引き起こすのはなぜですか?
私はここで関数を呼び出しています:
// Personnel listing
upp_loop('Personal', 'personnel-preview', '<section class="res-table">', '</section>');
そして、これはポストを生成するコードです:
// Loop through children (To make headers)
$cats = get_categories('child_of=' . $catID . '&orderby=count&order=DESC');
foreach ($cats as $cat) :
$args = array(
'cat' => $cat->term_id
);
$query = new WP_query($args);
if ($query->have_posts()) :
// Echo the Category name
?> <h2><?php echo $cat->name; ?></h2> <?php
// List all children
while($query->have_posts()) :
$query->the_post();
if (has_post_thumbnail()) {
$img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
}
else {
$img[0] = get_template_directory_uri() . "/img/program-default.png";
}?>
<a href="<?php the_permalink(); ?>" class="res-td">
<img src="<?php echo $img[0] ?>" alt="<?php the_title(); ?>"/>
<h2><?php the_title() ?></h2>
</a>
<?php
endwhile;
endif;
endforeach;
に
$query->have_posts()
the_post()
にquery_posts($args)
have_posts()
$query = query_posts($args)
にします4002/querying-posts#t = 201608150832028118879)。これに対して 'query_posts'を使わないでください... –@dingo_d私は新しいWP_queryオブジェクトを作成しましたが、今は無限に固執しません。しかしそれは4回foreachを行います。どんな考え? –
もしあなたが4つのカテゴリを持っていれば、foreachは4回しか行われません。 –