感谢@pietergoosen“开玩笑地”给了我答案。
function gm_gather_posts_in_array() {
$set_days_before = \'1275\';
$posts_to_be_processed = date(\'Y-m-d\', strtotime("today - $set_days_before days"));
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'posts_per_page\' => -1,
\'fields\' => \'ids\',
\'date_query\' => array(
array(
\'before\' => $posts_to_be_processed
)
)
);
$posts_to_be_processed = new WP_Query( $args );
return $posts_to_be_processed;
}
function gm_update_posts_to_be_archived() {
$posts_ready_to_be_processed = gm_gather_posts_in_array();
if ( $posts_ready_to_be_processed->have_posts() ) {
while ( $posts_ready_to_be_processed->have_posts() ) {
$posts_ready_to_be_processed->the_post();
$process_post = array(
\'ID\' => get_the_id(),
\'post_type\' => \'custom_post_type\',
);
wp_update_post( $process_post );
}
}
wp_reset_postdata();
}
echo gm_update_posts_to_be_processed();