A Post is saved twice or more during add_action(save_post)

One of the two IDs might be a post revision. To prevent this behaviour, I always have this checks in my save_postdata function: // Autosave, do nothing if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; // AJAX? Not used here if ( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) return; // Check user permissions if … Read more

save_post action firing before I publish / save the post

A draft or “blank” is saved as soon as you start to create a new post. Those new posts have the post_status of auto-draft. Check for that to prevent your callback from firing on those “blank” post saves. function update_test( $post_id, $post ) { if (isset($post->post_status) && ‘auto-draft’ == $post->post_status) { return; } update_post_meta($post_id, ‘copied’, … Read more

Wp_update_post: Infinite loop even with remove_action solution, OOP

You need to match the $priority you used to hook the action: remove_action( ‘save_post’, array( $this, ‘save_box’ ), 20 /* Same as add_action call */ ); http://codex.wordpress.org/Function_Reference/remove_action Make sure you take the $post_id argument in your save_box method too: function save_box( $post_id ) { … }

WP Rest API – Upload media without saving attachment post

Based on your comment you appear to be using the REST API. There’s no hook between uploading the file and creating the attachment post that could be used for this purpose in the API endpoint. The best you can do appears to be to use the rest_insert_attachment action. It provides callback functions with the WP_Post … Read more