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);

Use WP Title instead of custom field to call

You’re passing too many arguments to urlencode. WordPress provides a couple of useful functions for these situations. add_query_arg is a helper to build a URL with query arguments, and esc_url provide sanitation and validations relevant to encoding URLs. Also, wp_title will display or return a combination of the page/post title and a seperator, which doesn’t … Read more