【问题标题】:wp_query infinite loop unable to resolvewp_query 无限循环无法解决
【发布时间】:2018-04-13 13:03:35
【问题描述】:

我很欣赏这里有数百万个 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>';

我认为应该解决循环问题,页面加载到查询并挂起,直到达到执行超时。

关于问题可能是什么的任何想法?

【问题讨论】:

    标签: php wordpress loops while-loop


    【解决方案1】:

    我想你忘记添加 the_post()

    在循环中迭代帖子索引。

    <?php if ( $the_query->have_posts() ) { the_post(); 
    

    https://developer.wordpress.org/reference/functions/the_post/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 2020-05-18
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多