wp_after_insert_post() WordPress Function

The wp_after_insert_post() function is used to perform an action after a new post has been inserted into the database.

wp_after_insert_post( int|WP_Post $post, bool $update, null|WP_Post $post_before ) #

Fires actions after a post, its terms and meta data has been saved.


Parameters

$post

(int|WP_Post)(Required)The post ID or object that has been saved.

$update

(bool)(Required)Whether this is an existing post being updated.

$post_before

(null|WP_Post)(Required)Null for new posts, the WP_Post object prior to the update for updated posts.


Top ↑

Source

File: wp-includes/post.php

function wp_after_insert_post( $post, $update, $post_before ) {
	$post = get_post( $post );
	if ( ! $post ) {
		return;
	}

	$post_id = $post->ID;

	/**
	 * Fires once a post, its terms and meta data has been saved.
	 *
	 * @since 5.6.0
	 *
	 * @param int          $post_id     Post ID.
	 * @param WP_Post      $post        Post object.
	 * @param bool         $update      Whether this is an existing post being updated.
	 * @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
	 *                                  to the update for updated posts.
	 */
	do_action( 'wp_after_insert_post', $post_id, $post, $update, $post_before );
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More