如果需要按文章发布日期升序更新的话(也就是先更老文章),将代码改成如下即可:
function update_all_posts() {
$args = array(
'post_type' => 'post',
'numberposts' => -1,
'orderby' => 'post_date',
'order' => 'ASC',
);
$all_posts = get_posts($args);
foreach ($all_posts as $single_post){
$single_post->post_title = $single_post->post_title.'';
wp_update_post( $single_post );
}
}
add_action( 'wp_loaded', 'update_all_posts' );
老实说,我非常不理解你这个需求,甚至于感觉匪夷所思。我无法理解为什么文章的更新时间会影响文章的顺序,但是还是按你的需求修改了一下代码。