Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WP_查询在插件WP_AJAX中不起作用_Ajax_Wordpress - Fatal编程技术网

WP_查询在插件WP_AJAX中不起作用

WP_查询在插件WP_AJAX中不起作用,ajax,wordpress,Ajax,Wordpress,我正在制作一个插件,并在其中使用ajax 我将此代码放在main.php中,但在WP_查询行中出现了致命错误 function my_ajax() { header( 'Content-Type: text/html; charset=utf-8' ); $args = array( 'post_type' => 'post', 'posts_per_page' => -1, ); $the_query = new WP_Query( $args );

我正在制作一个插件,并在其中使用ajax

我将此代码放在main.php中,但在WP_查询行中出现了致命错误

function my_ajax() {
  header( 'Content-Type: text/html; charset=utf-8' );
  $args = array(
    'post_type' => 'post',
    'posts_per_page' => -1,
  );
  $the_query = new WP_Query( $args );
  if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ):
      $the_query->the_post();
      echo $the_query->post->ID;
    endwhile;
    wp_reset_postdata();
  }
  die();
}

add_action( 'wp_ajax_my_ajax', 'my_ajax' );
WP_查询无法在WP_ajax中工作? 可能是,wp_查询在wp_ajax之前未加载。 那么,有没有办法自己或其他人加载WP_查询类? 如果你知道像Chuck Norris空手道踢腿那样的力量之道,我不在乎,只是想得到一个解决


注意。

原因是PHP内存不足。我在测试中发了2000篇文章。 我把它放在wp-config.php中

define( 'WP_DEBUG_LOG', true );
我可以看到login/wp contents/debug.log,这表示内存已满

所以我换了$arg 缩小范围的参数,WP_查询工作


尊敬。

我自己解决了。