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 )
2 s
It’s wp_insert_post()
vs.
wp_update_post()
– where update will ultimately also call:
return wp_insert_post( $postarr, $wp_error, $fire_after_hooks );
The term “once” implies that it is being fired “afterwards”.
/**
* Fires once a post has been saved.
*
* @since 1.5.0
*
* @param int $post_ID Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated.
*/
do_action( 'save_post', $post_ID, $post, $update );
When inserting a post, save_post
is being fired while $fire_after_hooks
is true
.
And usually one may want to insert/update the record and not only fire the hook …