Why doesn’t wp_update_post() update the post_status field?

Answer couldn’t be simpler. As pointed out by Otto at the wp-hackers list, problem was me not setting post_date_gmt when using wp_update_post(). Final code looks like this: if ( $post_date < strtotime( “tomorrow” ) ) { $status=”publish”; $newpostdata[‘post_status’] = $status; $newpostdata[‘post_date’] = date( ‘Y-m-d H:i:s’, $post_date ); // Also pass ‘post_date_gmt’ so that WP plays … Read more

Connection lost. Saving has been disabled… (Updating Posts/Pages)

That message is a result of your server throwing a 503 error and the WordPress Heartbeat API catching that error. See https://core.trac.wordpress.org/ticket/25660 for the background on the fix that WordPress introduced to save offline edits. Things to check on your computer are if WAMP is actually running when you’re getting this message (check the status … Read more

How to avoid infinite loop in save_post callback

You can remove the callback from the save_post hook, update the post and then re-add the call back to the hook. The Codex gives an example. add_action(‘save_post’, ‘wpse51363_save_post’); function wpse51363_save_post($post_id) { //Check it’s not an auto save routine if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return; //Perform permission checks! For example: if ( !current_user_can(‘edit_post’, $post_id) ) … Read more

Check for update vs new post on save_post action

Since WordPress version 3.7. – IIRC – the save_post hook – more information about the hook and its usage at Code Reference: save_post and Codex: save_post – has a third parameter $update which can be used to determine just that. @param     int               $post_ID     Post ID. @param     WP_Post     $post          Post object. @param … Read more