Have you checked here? It’s a pretty complete guide.
Thread Starter
stuk88
(@stuk88)
yup already checked there…
i didnt able to find any “new_post” like, hook.
Thread Starter
stuk88
(@stuk88)
There is any way to hook to a new post creation?
Anyone?
save_post Runs whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. Action function arguments: post ID.
Thread Starter
stuk88
(@stuk88)
yea i know that didnt help me in the first time either..
my quastion was how to check if the saved post was a new post or just an update to an exiting post…
I already found a way to check this…
new post doesnt have any id set to it yet.
so the code looks like that:
if($post->post_parent == 0 && $post->post_type == 'post' && !$post->ID)
i had to do some other check on deleted post either, because the “delete_post” hook run whenever a post data deleted… page or post or revision…
I’m using the next code to handle the first time post publish event.
WordPress 3.0+ required.
add_action( 'publish_post', 'run_when_post_published_first_time',10,2 );
function run_when_post_published_first_time($post_id, $post)
{
// Checks whether is post updated or published at first time.
if ($post->post_date != $post->post_modified) return;
// Place here your code
}
P.S. Sorry for my english.