Php ';每页张贴'=&燃气轮机-1不工作
我想通过$arg中的所有帖子运行一个查询,但它只适用于11篇帖子。我尝试了很多论坛上的建议,但都没能奏效 我需要做什么Php ';每页张贴'=&燃气轮机-1不工作,php,wordpress,Php,Wordpress,我想通过$arg中的所有帖子运行一个查询,但它只适用于11篇帖子。我尝试了很多论坛上的建议,但都没能奏效 我需要做什么 function test_update_random_number() { global $post; $args = array ( 'orderby' => 'meta_value LIKE "%Yes%" rand', 'order' => 'DESC',
function test_update_random_number()
{
global $post;
$args = array (
'orderby' => 'meta_value LIKE "%Yes%" rand',
'order' => 'DESC',
'meta_key' => 'feature_in_search',
'post_type' => 'therapist',
'post_status' => 'publish',
'posts_per_page' => '-1'
);
$myposts = new WP_Query( $args );
if ( $myposts->have_posts() ) :
while ( $myposts->have_posts() ) : $myposts->the_post();
$value = get_field( "feature_in_search", $post_id );
if ( strpos( $value, 'es' ) !== false ) {
$random_value = rand( 1, 100 );
update_field( "field_58aebd8e060c0", $random_value, $post_id );
} else {
$random_value2 = rand( 100, 600 );
update_field( "field_58aebd8e060c0", $random_value2, $post_id );
}
endwhile;
wp_reset_postdata();
endif;
}
问题不在于
posts\u per\u page
参数,而在于orderby
参数
您有像“%Yes%”rand这样的'orderby'=>元值,
,这没有多大意义。另外,如果您想随机订购,订购ASC
或DESC
也没有意义…:)
显然,您希望筛选所有具有meta_字段“feature_in_search”且值为“Yes”的帖子,并对其进行随机排序。所以你应该:
$args = [
'meta_key' => 'feature_in_search',
'meta_value' => 'Yes',
'post_type' => 'therapist',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'rand'
];
如果您真的想搜索包含“Yes”(并使用“LIKE”搜索)的内容,则需要构造一个适当的。您的问题不在于
posts\u per\u page
参数,而在于orderby
参数
您有像“%Yes%”rand这样的'orderby'=>元值,
,这没有多大意义。另外,如果您想随机订购,订购ASC
或DESC
也没有意义…:)
显然,您希望筛选所有具有meta_字段“feature_in_search”且值为“Yes”的帖子,并对其进行随机排序。所以你应该:
$args = [
'meta_key' => 'feature_in_search',
'meta_value' => 'Yes',
'post_type' => 'therapist',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'rand'
];
如果你真的想搜索包含“Yes”(并使用“LIKE”搜索)的内容,你需要构造一个合适的参数。我认为你错了参数类型
'posts\u per\u page'=>'-1'//这个参数必须是int
——请看文档不是说-1是一个选项吗?我尝试了大量类似posts\u per\u page'=>500的参数。它也不起作用。请尝试使用'posts\u per_page'=>-1
并删除元键和orderby
也许您可以使用此参数。删除元键和orderby会使它起作用,但为什么它不能使用元键?我需要那个子句?Makeorderby=>rand
并且对于meta\u value
选择使用meta\u query
和'compare'=>'LIKE'
我想你错了param变量类型'posts\u per\u page'=>'-1'//这个参数必须是int
--文档没有说-1是一个选项吗?我尝试了很多类似的参数每页的帖子“=>500。它也不起作用。请尝试使用'posts\u per_page'=>-1
并删除元键和orderby
也许您可以使用此参数。删除元键和orderby会使它起作用,但为什么它不能使用元键?我需要那个子句?Makeorderby=>rand
并且对于meta\u值
选择使用meta\u查询
和'compare'=>LIKE'