Normally you can update any post’s date using the Editor window. For example, if you choose a future date and then publish that post, WordPress will automatically set it to Scheduled status. Ever wondered how you can do it using a php code?
Here is a short snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php // Get the post ID $post_ID = 35; // Set our date to a variable $post_new_date = date('Y-m-d h:s'); // setting current date // Make an array holding the updated date $post_info = array( "ID" => $post_ID, "post_date" => $post_new_date, "post_date_gmt" => $post_new_date, "post_status" => 'future' ); ?> |
Assuming 35 as a post ID, we are updating its date only using the above code. You have to set post_date and post_date_gmt both to the new date. also the post_status must be set to future which will make the actual status of post to be Scheduled.
the variable $post_new_date can have the new date information, you can assign whatever new date to that variable.
Hope it helps.