Automatically Add a default category to a Custom Post Type before save_post action

the hooks “save_post…” are called too when a new post is created

then you can set default values with that

$customPostType = "customTypeCode";

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


    if (!$update) {

        // new item
        // place to set default values


        return;

    }


    // updating a existing item
    // ...



}, 10, 3);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)