[英]WP_query issues using posts_per_pages -1
这有点怪异,我需要一些有关WP_query()问题的帮助或解释;
当您到达特定页面时,我的代码通过meta查询获取所有帖子类型的项目:
echo 'apple';
$args = array(
'post_type' => "family",
'meta_query' => array(
array('key' => '_family')
),
'posts_per_page'=>'9000' // number post in this post type: 18 000 entries
);
$my_query = new WP_Query($args);
echo 'banana';
如果我在页面加载时使用..还可以..我看到我的“香蕉”回声。
如果我在“ ajax”中执行此操作,则返回的值为“ null”,并且没有看到“ banana”,但是看到了“ apple”
我已经尝试过posts_per_page =>'3'在ajax中工作正常。
测试:
posts_per_page=>'3' [OK]
posts_per_page=>'-1' [FAILED]
posts_per_page=>'2000' [FAILED]
另外,我们在php.ini上有4Go作为memory_limit。
如果我以“ safe_mode On”运行,一切正常。
任何想法?
谢谢!
编辑
$('body.woocommerce-account #famille-list a').on('click',function (e){
if($(this).data('action') == "edit"){
e.preventDefault();
showProgress();
jQuery.ajax({
type: "post",
dataType: "json",
async: true,
url: scriptParams.ajaxurl,
data: {
action: "edit_family",
id: $(this).data('id')
},
success: function(data) {
if(data != null && data.success == 1){
if($('form.myfamily').css('display')=='none'){
$('form.myfamily').prev().find('h3').click();
}
$('input[name=save_children]').val('Modifier');
$('input[name=id]').val(data.member.id);
hideProgress();
}
}
});
}
});
对于AJAX,请求只应包含一个使用json_encode
传递的echo
语句,然后再包含die()
语句。 如果这不能解决您的错误,则至少是个好习惯,因为它可以清楚地表明您的HTTP响应是什么。
header( "Content-Type: application/json" );
echo json_encode('apple');
die();
// Code should not reach your banana statement
因此,对于您的代码,您应该这样做:
$response = array();
$response[] = 'apple';
$args = array(
'post_type' => "family",
'meta_query' => array(
array('key' => '_family')
),
'posts_per_page'=>'9000' // number post in this post type: 18 000 entries
);
$my_query = new WP_Query($args);
$response[] = 'banana';
header( "Content-Type: application/json" );
// will return an array with the value ['apple', 'bannana'];
echo json_encode($response);
die();
另外,您是否要直接调用PHP文件? 这是WordPress的不良做法。 有一种已建立的处理AJAX请求的方法: http : //codex.wordpress.org/AJAX_in_Plugins (它说它是用于插件的,但是主题也可以使用它)。 刚开始时有点罗and且难以理解,但更加干净灵活。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.