wp_insert_post WordPress Action Hook

The wp_insert_post hook is triggered when a post is inserted into the database. It allows you to modify the post before it is saved to the database.

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

Fires once a post has been saved.


Parameters

$post_ID

(int)Post ID.

$post

(WP_Post)Post object.

$update

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


Top ↑

More Information

The wp_insert_post action fires once a post has been saved. You have the ability to set it to only fire on new posts or on all save actions using the parameters. Please see Plugin_API/Action_Reference/save_post for more information. Keep in mind that this action is called both for actions in the admin as well as anytime the wp_insert_post() function is invoked.

This action can be replicated by creating a conditional in a save_post action that excludes certain post statuses.

An important distinction of wp_insert_post action is that it is fired after update_post_meta has been called.


Top ↑

Source

File: wp-includes/post.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.0.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