[英]wp_query infinite loop unable to resolve
我很欣賞這里有數百萬個wp_query無限循環問題,我已經瀏覽並試圖找到答案,但是到目前為止,似乎沒有什么合適的選擇!
我要編寫的wp_query應該很簡單,但顯然我的代碼中缺少一些東西;
$args = array ('cat' => 2893);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
echo '<li>' . the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
echo '<p>nothing</p>';
}
上面的代碼導致標題無限循環,但是當我將回顯線更改為
echo '<li>' . $the_query->the_title() . '</li>';
我認為這應該可以解決循環問題,頁面會加載到查詢為止並一直掛起,直到達到執行超時為止。
關於可能的問題有什么想法?
我認為您忘記添加the_post()
在循環中迭代發布索引。
<?php if ( $the_query->have_posts() ) { the_post();
https://developer.wordpress.org/reference/functions/the_post/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.