{$new_status}_{$post->post_type} WordPress Action Hook

The {$new_status}_{$post->post_type} hook is triggered when a post of the type $post->post_type changes its status to $new_status. This hook can be used to perform an action when a post's status is changed. For example, you could use this hook to send an email notification or update a custom field in the post.

do_action( "{$new_status}_{$post->post_type}", int $post_id, WP_Post $post, string $old_status ) #

Fires when a post is transitioned from one status to another.


Description

The dynamic portions of the hook name, $new_status and $post->post_type, refer to the new post status and post type, respectively.

Possible hook names include:

  • draft_post
  • future_post
  • pending_post
  • private_post
  • publish_post
  • trash_post
  • draft_page
  • future_page
  • pending_page
  • private_page
  • publish_page
  • trash_page
  • publish_attachment
  • trash_attachment

Please note: When this action is hooked using a particular post status (like ‘publish’, as publish_{$post->post_type}), it will fire both when a post is first transitioned to that status from something else, as well as upon subsequent post updates (old and new status are both the same).

Therefore, if you are looking to only fire a callback when a post is first transitioned to a status, use the ‘transition_post_status’ hook instead.


Top ↑

Parameters

$post_id

(int)Post ID.

$post

(WP_Post)Post object.

$old_status

(string)Old post status.


Top ↑

Source

File: wp-includes/post.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
5.9.0Added $old_status parameter.
2.3.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