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) )
return;
//Check your nonce!
//If calling wp_update_post, unhook this function so it doesn't loop infinitely
remove_action('save_post', 'wpse51363_save_post');
// call wp_update_post update, which calls save_post again. E.g:
wp_update_post(array('ID' => $post_id, 'post_status' => 'private'));
// re-hook this function
add_action('save_post', 'wpse51363_save_post');
}
Related Posts:
- Check for update vs new post on save_post action
- Clear cache on post of one type when something happens to post of other type
- Custom wp_editor doesn’t update post_content
- $update is always true in save_post
- Action hook ‘save_post’ triggered when deleting posts
- get post meta before it is updated (during SAVE_POST)
- Wp_update_post: Infinite loop even with remove_action solution, OOP
- save_post action firing before I publish / save the post
- save_post action only when creating a new post
- Check if value has changed on save_post
- Minimum Word Count Before A Post Can Be Made Pending Review
- update_post_meta() not working in save_post
- How do I save each option in a multiple select menu as it’s own meta_key + meta_value pair?
- Update post on save
- Post meta checkbox becomes unchecked occasionally
- Return code from save_post action?
- update_post_meta not working in save_post
- save_post only saves meta data on second save
- Get Post ID with insert/edit link
- How to manage saving custom field from Quick edit and Post Save using save_post action hook without colliding each other?
- post_status => publish not working
- Why save_post_$(custom_post_type) is fired even if I am not already saving a post?
- Set the value of custom field when post is published or updated
- How to catch and modify custom field values when a page is updated
- pass error to admin_notices on “quick edit”/save_post action
- save_post requiere at least one uploaded file to be published
- Get $_POST & $_REQUEST values before adding/updating post
- How can I create a new user account while creating a new post, and then set that new user as the author of that new post?
- Validate post checking if child term is assigned
- Why not fire the save_post event?
- Compare custom taxonomies of updated post (or new post) [Updated with progress]
- WordPress 4.9.8 doesn’t save if content has style=”
- Reset all transients on post or page save
- Using PODS data with save_post
- Cant’t delete my custom posts
- where does this $post_id come from?
- Update current WP post every 3 minutes [closed]
- Changing new post to “pending” on publish – but “Publish failed” – why?
- Custom Meta Box (SELECT2) Not Saving Taxonomy Terms
- update_post_meta not working in foreach
- Save post in another table
- Strange bug on post/page save
- draft_to_pending action doesn’t seem to fire
- What action to use for when a post is saved / published, with a caveat
- Save custom value to main content of post
- Check for page template on save_post hook
- Access NEW/UPDATED post values in save_post() callback function
- remove_action(‘save_post’) in function that was triggered by save post not working
- save button grayed out randomly
- save_post affect creation and deletion
- Post editor doesn’t save embed media [closed]
- How to get a post meta value and pass that to update_option when a post is created or updated?
- WordPress save meta data : Displaying the word Array when selected
- Save current post using custom save button
- set_post_format called after wp_update_post when using bulk edit?
- Connection Reset on post/page save
- Meta data not saved on save_post
- Insert/Update DB table when making new post or update older one
- Prevent Page/Post From Being Created based on Pages/Posts per User per Time Unit
- How to debug | Some times the “Save Draft” button seems to spin but does not actually save
- My custom title gets duplicated at every save or post update
- Taxonomy Child Not Updating Unless I Click Update Twice
- Use save_post to generate file on wordpress
- Set post status to draft after validating post meta values in save_post hook
- Detect, if post is saved manually or programmatically in save_post-hook
- How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?
- Updating a post without escaping ampersands?
- Is there an easy way to AJAX-ify saving of post?
- Check before publishing, if already exist post with current custom field value
- change a post status when users update posts?
- “Notice: Undefined index:” error when adding new content?
- Get the post_id of a new post
- Get updated post meta on save_post action?
- Delete post meta conditionally after save post
- Faking the “onSave” event
- Undefined ‘post_type’ error on Add new page
- using new WP_Query in save_post function alters $post
- Insert and then update post_type by wp_update_post
- How can I set taxonomy programmatically
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Programmatically save one/any post
- wp_update_post not working
- Checked() function on a multidimensional array
- Mutiple Select only POSTing 1 value
- Allow only one post with specific meta value
- Custom metabox not displaying multiselect data in edit mode
- How to validate select field in post meta?
- Update post meta within save_post action
- How to create a front facing user sign up, log in and profile pages like FoodGawker.Com [closed]
- Bulk update published posts date randomly using wp-cli?
- Autopopulate a value
- wp_trash_post() duplicates post to trash
- update a custom field with the value of another existing custom field
- save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash
- Link two different post using there post_id in post meta
- Why WordPress takes time to make request to save post?
- A correct hook for saving meta boxes data
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- wp_update_post behaves differently for different user role
- Update user from external script