Original save_ Post and related action hooks can also be used for this purpose, but they are triggered in scenarios other than classic editors (for example, in the rest API, in the customizer, and when creating automatic drafts) before category items and metadata are updated.
The new hook can send up to three parameters:
$post_ Id the updated article ID is an integer. $post is the complete object of the updated article, that is, WP_ Post object. $updated whether the article has been updated is a Boolean value.
By default, WordPress is in WP_ insert_ This hook is triggered at the end of post(). A third parameter is added to the function to allow developers to prevent the hook from triggering automatically:
$fire_ after_ Does hooks insert WP_ after_ insert_ Post hook, Boolean value, optional, true by default.
The same parameters have been added to WP_ update_ Post () is added to WP as the third parameter and_ insert_ Attachment () as the fifth argument.
If developers call any of these functions and prevent hook triggering, they can expect to call the new function WP manually_ after_ insert_ Post () to trigger a new action. This new feature requires two parameters:
$post saved article ID or object, integer or WP_ Post object $update whether the article has been updated, Boolean value.Simple example
If you are calling WP_ insert_ Post () or one of the related functions listed above, it is recommended that you prevent the hook from running and call it manually if you subsequently update the category item or metadata of the article respectively. For example:
$post_id = wp_insert_post( array( 'post_title' => 'My post title', 'post_content' => 'My post content', 'post_type' => 'my_cpt', ), false, false ); add_post_meta( $post_id, 'my_meta_key', 'my meta value' ); wp_after_insert_post( $post_id, false ); // Second parameter is true for an updated post.
For more information, please see the official log.