I have managed to update post meta using update_post_meta(). However, the more posts I have, the more time it takes. I would like to minimize the time it takes to process say about 400 posts (although I am not too sure how long this will take). Currently my code looks like this:
$numbers = range(1,100000);
shuffle($numbers); //Randomizing the index (no duplication at all)
$count = 0; //Begin with an index of 0
$args = array(
'post_type' => 'xn_group',
'post_status' => 'publish'
);
//This should get all the posts of xn_group, all of these posts will get the value of its meta_key 'xn_group_order' shuffled (randomized daily).
$the_query = new WP_Query($args);
//DIRECT QUERYING...(to reduce time complexity)
while($the_query->have_posts()) : $the_query->the_post();
update_post_meta(get_the_ID(), "xn_group_order", $numbers[$count]);
//$count += mt_rand(1,10); //Another technique to ensure fair randomization (not necessary).
$count += 1;
endwhile;
wp_reset_query();
However, I worry that as posts get bigger, the changes made will cost a lot. So I would like to ask the better way to achieve this. Perhaps using SQL statement? Any ideas?