[wp-hackers] Single Action hook for _new_ posts of any type?

Peter Adams peter at oncefuture.com
Tue Aug 3 22:28:35 UTC 2010


right. thanks. 
But how do you tell if it's an auto-save that is firing the hook? 
Seems like this hook shouldn't get called on an auto-save but it does from what i can tell...

-P-

On Aug 3, 2010, at 11:36 AM, Otto wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list