Reputation: 1761
I would like to run a query through all the posts in the $arg but it is only working for 11 posts. I've tried many suggestions from forums but I can't get it to work.
what do I need to do?
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;
}
Upvotes: 0
Views: 2530
Reputation: 47380
Your problems is not with the posts_per_page
parameter, but with the orderby
parameter.
You have 'orderby' => 'meta_value LIKE "%Yes%" rand',
, which doesn't make much sense. Also, if you want to order randomly, ordering ASC
or DESC
doesn't make sense either... :)
Apparently you want to filter all the posts that have a meta_field "feature_in_search" with a value of "Yes", and randomly sorted. So you should do:
$args = [
'meta_key' => 'feature_in_search',
'meta_value' => 'Yes',
'post_type' => 'therapist',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'rand'
];
If you really want to search for things that contain "Yes" (and use a "LIKE" search) you would need to construct a proper meta query.
Upvotes: 3