Is there a way to trigger the post saving or updating event in code? such as do_action('save_post', $post_id); The function here seems to imply that a WP_POST object needs to be passed in. Is there a way to basically imitate the action of updating the post with all its existing values. The point is for the other hooks linked to all trigger on post update. Maybe do a wp_insert_post(), just passing in the post id?

do_action( 'save_post', int $post_ID, WP_Post $post, bool $update )

  • Not quite following "other hooks linked to all trigger" - could you clarify what you're trying to accomplish? It sounds like more than just adding a new revision to the db. – WebElaine Apr 24 '17 at 19:33
  • I want to trigger all the hooks hooked to save_post that's why I'd like to trigger the event somehow. – TurtleTread Apr 24 '17 at 21:02
  • What is your goal in triggering all of the hooks? If you explain a bit more we may be able to help you think of another solution that's cleaner. – WebElaine Apr 25 '17 at 15:09
  • Other plugins have hooks linked to save_post that I want to trigger. – TurtleTread Apr 25 '17 at 15:44
  • why you don't want to use the function wp_insert_post ? – mmm Apr 25 '17 at 19:48

The answer to your question is to call do_action with the correct parameters. However, I would like to know more about why you're doing this - is there a post your saving programmatically?

  • 3
    There are multiple hooks in the system related to save_post event that I want to trigger for the posts. – TurtleTread Apr 25 '17 at 13:32
  • Not sure why the downvote. The best way to trigger all the actions related to save post is to call either wp_insert_post or wp_update_post – Welcher Dec 1 '19 at 14:29
  • I think it was downvoted because it doesn't provide much insight into the problem and it could just as well have been a comment rather than an answer. – admcfajn May 14 '20 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.