Assume I created a new post type 'product'
. Is there a way to perform a function (user created) when this new 'product'
post has been created?
Leave a Reply
You must be logged in to post a comment.
Assume I created a new post type 'product'
. Is there a way to perform a function (user created) when this new 'product'
post has been created?
You must be logged in to post a comment.
In functions.php:
For more and the official documentation, refer here:
http://codex.wordpress.org/Post_Status_Transitions
Hi @dotty:
Take a look at the end of the
wp_insert_post()
function in the file/wp-includes/post.php
(on lines 2148 thru 2392 in WordPress 3.0.1. Note that WordPress uses this function both for adding and updating posts.)At the end it has the following code. From this code you can identify the call to
wp_transition_post_status()
(more on that in a bit) and we have the action hooksedit_post
,post_updated
,save_post
andwp_insert_post
(frankly I don’t know why we have the latter two instead of just one.) You can use any of those that are appropriate for your needs:And as @Jan Fabry mentioned there are the action hooks found in
wp_transition_post_status()
(on 2713 thru 2717 of/wp-includes/post.php
in WordPress 3.0.1.) Note there are three of them; use as appropriate:The
wp_transition_post_status
function will be called, and this will trigger the action"${new_status}_$post->post_type"
, so if aproduct
moves to thepublish
state, the actionpublish_product
will be triggered.