我已经使用update\\u post\\u meta()更新了post meta。然而,我的帖子越多,花的时间就越多。我想尽量减少处理400个帖子所需的时间(虽然我不太确定这需要多长时间)。当前我的代码如下所示:
$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();
然而,我担心,随着帖子越来越大,所做的更改将花费很多。因此,我想问一个更好的方法来实现这一点。可能使用SQL语句?有什么想法吗?