[wp-hackers] Single Action hook for _new_ posts of any type?
Otto
otto at ottodestruct.com
Tue Aug 3 18:36:53 UTC 2010
On Tue, Aug 3, 2010 at 12:55 PM, Peter Adams <peter at oncefuture.com> wrote:
> Picking this back up...
>
> This hook seems to get fired during auto-saves. Is there a way to detect auto-saves when a post's status is transitioned?
>
> Looking for a way to tease out true post "edits".
The transition_post_status hook gets fired a lot. But you can compare
the old and new post status to know what's going on.
add_action( 'transition_post_status', 'whatever', 10, 3 );
function whatever( $new, $old, $post ) {
// compare $new and $old and act accordingly
}
Basically, when $new is publish and $old is anything else, then you
know a post is getting published for the first time. Or whatever your
own criteria are. You can also examine $post to check for other
things, like post_type or something. If it doesn't fit your criteria,
just return without doing anything.
-Otto
More information about the wp-hackers
mailing list