• Resolved Anonymous User 18578383

    (@anonymized-18578383)


    Hi, looks like there is a conflict of ACF Extended with ACF PRO plugin.

    My website is celebratufiesta.com

    Each time that I upload a featured image for normal posts or pages, the image doesn′t save.

    I deactivated the plugin (ACF Extended) to test and all worked fine.

    By the way, all the custom fields that I created only apply to users or to custom posts (no pages or normal posts). So there is any bad configuration.

    Do you have one idea of what is going on?

    Thanks in advance.

    Fernando

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. I just tested it, and the featured image works fine with ACF Pro 5.9.5, ACF Extended 0.8.8.1, on a fresh WP 5.7 install with a blank theme (both with & without Classic Editor). Video showcase: https://i.imgur.com/vpizBVi.mp4

    Can you please make sure that you don’t have an ACF image field with “Set as Featured Image” setting on your post type (as it will override the native Featured Image if the field is left empty)?

    If you have other plugins (especially additional ACF plugins), or some custom code, you can try to disable them one-by-one, maybe there’s an incompatibility with one of them.

    Hope it helps!

    Regards.

    Thread Starter Anonymous User 18578383

    (@anonymized-18578383)

    Hi Konrad,

    thanks a lot for your message.

    I have established an image (uploaded through a custom field) as a Featured Image of a specific Custom Post Type (name:Artistas).

    Below, I attached a video where I explain you in detail the problem. Also you will see the plugins are installed on my website and some custom codes.

    https://www.loom.com/share/ceb8d7aa189c4072bb3d7150f46a2802

    If it is neccesary, I can give you access to my website.

    I look forward to hearing from you.

    Thanks again
    Fernando

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback and the video (you may want to keep it private tho, since you display private part of production website). There’s a lot of plugins and custom code here which could create compatibility issues tho.

    I would recommend to clone your website using a plugin like Duplicator and install your website on a local environment to avoid crashing your production.

    Regarding your problem, it looks like it is caused by the code you’re using the set the Image Crop field as featured image, from this topic:

    add_action('acf/save_post', function ($post_id) {
        $value = get_field('my_crop_image_field', $post_id);
        if ($value) {
            if (!is_numeric($value)) {
                $value = $value['ID'];
            }
            update_post_meta($post_id, '_thumbnail_id', $value);
        } else {
            delete_post_meta($post_id, '_thumbnail_id');
        }
    }, 11);
    

    The problem with this code is that everytime a page with ACF fields is saved in the back-end, it will try to to retrieve my_crop_image_field, and if it is not there it will delete the featured image in else { delete_post_meta($post_id, '_thumbnail_id'); }.

    In your example, the field my_crop_image_field doesn’t exists on the post type Page so it will always delete the featured image.

    Now the question of “Why disabling ACF Extended seems to fix the problem”:

    By default, ACF will trigger the acf/save_post hook when there at least 1 ACF field on the page. It looks like you have no ACF fields on the Post Type Page, so without ACF Extended acf/save_post is not triggered, so my_crop_image_field is not checked and the featured image is not deleted.

    With ACF Extended, the acf/save_post hook is triggered on your post type Page (even without any ACF Field) because ACF Extended inject a hidden field for the Ajax Authorbox module (The authorbox which let you change the author from the sidebar). So acf/save_post is triggered, the field my_crop_image_field is checked (but doesn’t exists) and the featured image is always deleted.

    This why you think disabling ACF Extended fix the issue, because you have no ACF Field on your post type page. Now I’ll show you that this issue is still there even when ACF Extended is disabled:

    You just have to create a “Test” field group, with one “Test Field” on the post type Page. This will trigger acf/save_post (and your custom code) on the post type Page, and the featured image will be always deleted, because there is no my_crop_image_field in there.

    Here is a video showing this: https://i.imgur.com/ieQosIY.mp4

    In this video, ACF Extended is disabled, I added your code in the functions.php and I created a “Test Field Group” with a simple “Text” field for the Post Type Page. You can try it yourself.

    To fix your issue, you have to enhance the code that check the my_crop_image_field field. I would recommend to check if $value === false instead (field is here on the page, but is empty). Code example:

    add_action('acf/save_post', function ($post_id) {
        
        $value = get_field('my_crop_image_field', $post_id);
        
        if ($value) {
            if (!is_numeric($value)) {
                $value = $value['ID'];
            }
            update_post_meta($post_id, '_thumbnail_id', $value);
            
        // Check if field is here AND empty
        } elseif($value === false) {
            delete_post_meta($post_id, '_thumbnail_id');
        }
        
    }, 11);
    

    Your code now works even if you have an ACF field on the post type Page and no my_crop_image_field.

    Hope it helps!

    Regards.

    Thread Starter Anonymous User 18578383

    (@anonymized-18578383)

    Your code worked like magic!

    The code I put on my website is:

    add_action('acf/save_post', function ($post_id) {
        $value = get_field('foto_principal_del_artista', $post_id);
        if ($value) {
            if (!is_numeric($value)) {
                $value = $value['ID'];
            }
            update_post_meta($post_id, '_thumbnail_id', $value);
    		
    // Check if field is here AND empty
        } elseif($value === false) {
             delete_post_meta($post_id, '_thumbnail_id');  
        }
    }, 11);

    All work fine! Thannk you very much!

    I followed your advice and I deleted the video.

    Have a great day!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear it now works as expected! Also, thank you for the nice review ??

    Have a nice day!

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conflict with ACF (featured image doesn’t save)’ is closed to new replies.