My question is,
Is there any filter or action that trigger when new post is insert in database..?
The reason behind it is I want to add key in post meta when new post is insert from admin side.
I got Action called "save_post"
but after refer link .This action trigger in created and update post.
but I only want to add meta key when post is created not at update time
You can use
wp_insert_post
so you will getpost_id
as soon as post inserted and you can then use that to addmeta_key
.If you are not using
wp_insert_post
and want to useaction
then you can simply put below code :which means that if you are updating the post, then it will return back from
function
.EDITED
Method-1 to achieve it.
You can simply check with the
get_post
method that post is there or not.something like below:Method-2 to achieve it.
But as you said there are many meta there, this method will be bit long.
Method-3 to achieve it.
You can do as rnevius suggested which is the one even I would opt. Its like :
or else you can do it with
draft_to_publish
like:You can refer codex for more information about post transition.
You're looking for
draft_to_publish
.