I've been searching in the codex from wordpress and search through google but didn't find any function or any code that can help me.

I want to build a conditional that when there is a new custom post type should do something automatically(in one case specific create a marker in a map).

Any suggestion?


  • When a Custom Post of a Post Type is created? The save_post hook is well enough for that, checking against the $post->post_type.
    – Howdy_McGee
    Nov 22, 2017 at 17:18

1 Answer 1


You can do something on a post creation with the action save_post_...

$customPostType = "custom";

add_action("save_post_" . $customPostType, function ($post_ID, \WP_Post $post, $update) {

    if (!$update) {
        // creation of the custom post
        // ...


    // updating of the custom post
    // ...

}, 10, 3);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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