4

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?

https://developer.wordpress.org/reference/hooks/save_post/
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
0

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?

  • 2
    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

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.