0

I have a custom post type no_resume and when a new post is created in it and a meta that is job_category is assigned to it I want to perform a function in which a mail will be sent to all the user that has that category in their database.

I tried save_post and publish_post and checked if meta exists in the database but save post fires before adding meta I want to execute that function only when a new post is created not when it is updated.

1

you can see all of wordpress action hooks here - I would suggest looking into something like "updated_postmeta" or similar for you

1

You could use the (status)_(post_type) hook. At publish for your specific CPT, query are there any other objects of the same type. If there are none, then this is your first post of the type.

add_action('publish_my_custom_post_type',function() {
    $posts = get_posts(array(
        'post_type' => 'my_custom_post_type',
    ));

    if(!empty($posts)):
        return; //There are posts of this type so we just return
    endif;

    //...Do what you want here
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.