0

I am using the Enhanced Image Library plugin to automatically add a taxonomy to images uploaded to a custom post type. The plugin has a feature that will allow the post's categories to be automatically added to associated images when the image is uploaded.

However, if the post category is not assigned to the post before the images are added, then the images will not be categorized correctly. The easiest solution would be if there was a way to assign a default category directly after the "New Post" button was clicked, before the user has a chance to input any data into the post fields, and well before the save_post action.

All of the answers to this question that I found seem to reference the save_post or publish_post actions. Is there any action that can be utilized when "new post" is initially clicked?

If there is not, do you have any other suggestions? Should I attempt to add javascript somewhere to pre-check this field in a post admin template? If so, where should I find that?

0

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);
  • Thanks for your response. My understanding is that the save_post hook fires when the "Publish" or "Update" button is clicked. Are you saying it also fires after the "New Post" button is clicked when the blank post admin screen is loading for the first time? If so, that would be great...I just haven't seen any comments that indicate that is the case. – Jonathan Dec 29 '17 at 23:39
0

As far as I can tell, there is no way to hook into the post when the 'new post' screen is initially generated. Instead, I loaded some javascript in the admin template and had the javascript check the category box for me.

  • Could you possibly write in your answer the script you wrote and where you placed it exactly? – Crimbo Jan 31 '18 at 12:45

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.