• Resolved Chris

    (@pma4life)


    When previewing a post, any ACF image field does not display, though when the post is published and viewed normally, the images appears correctly. To note, when &preview=true is removed from the preview url, the image displays properly. In addition, when the ACF Extended plugin is deactivated, the images work when posts are previewed.

    Please reach out if any other info is needed at this time. Thanks!

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I can’t seem to reproduce the issue. What code are you using on the front-end to display the image?

    Here is a video demo of my test: https://i.imgur.com/7YBlDJv.mp4
    Here is my front-end code to display the image:

    <?php if(have_posts()): ?>
        <?php while(have_posts()): the_post(); ?>
    
            <h1><?php the_title(); ?></h1>
            <?php echo wp_get_attachment_image(get_field('image')); ?>
    
        <?php endwhile; ?>
    <?php endif; ?>
    

    Do you use any advanced setting like “Set as Featured Image”? Or do you have an another ACF plugin which could interfere with the ACF Image field/Preview Mode?

    Regards.

    Thread Starter Chris

    (@pma4life)

    Hi Konrad, thank you for the quick response. I am sorry, I forgot to mention that this only occurs on posts that have the status of Pending or Draft, this issue does not occur on posts that have been Published. Here is the code to display the image:

    <figure class="eventHero__image">
        <img src="<?php echo esc_url($hero_image['url']); ?>" alt="<?php echo esc_attr($hero_image['alt']); ?>">
    </figure>

    But, again, the image displays when the post is previewed on a Published post, but not on Pending or Drafts. I hope that helps and thanks again!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I just tested it on a draft/pending review post and it works fine too.

    Here is a video demo: https://i.imgur.com/kivGcDM.mp4

    Front-end code:

    <?php $hero_image = get_field('image'); ?>
    
    <figure class="eventHero__image">
        <img src="<?php echo esc_url($hero_image['url']); ?>">
    </figure>
    

    There’s probably some compatibility issue somewhere on your install. In order to find it, I’ll need more information:

    • What is your WordPress & ACF Pro version?
    • Do you use Gutenberg or Classic Editor?
    • Do you have any other ACF plugin?
    • Can you please export your Image Field Group json? (ie: on pastebin.com)
    • Can you record a small screen capture like I did?

    Thanks in advance.

    Regards.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Any news?

    Regards.

    Thread Starter Chris

    (@pma4life)

    Hello Konrad,

    Sorry for the delay. Hoping we can resolve this without a screencast, but please let me know if that is vital. Below are the other requests:

    What is your WordPress & ACF Pro version?

    Wordpress Version: 5.8
    ACF Version 5.9.9

    Do you use Gutenberg or Classic Editor?

    Classic Editor with the Classic Editor plugin installed.

    Do you have any other ACF plugin?

    Advanced Custom Fields: Font Awesome

    Deactivating it results in the same issue of the image not displaying.

    Can you please export your Image Field Group json?

    https://pastebin.com/pwJPYRRf

    When I saw your example, it occurred to me that the image that is not appearing for us is within an ACF Group field. So I did a test with a single image not within a group and that worked on the same page where the image in the group still didn’t display. I believe that is the issue, but will let you investigate, hoping that bit of information helps. Please let us know if there is anything else at this time and really appreciate your time with this issue!

    • This reply was modified 3 years, 7 months ago by Chris.
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the details!

    I managed to reproduce the issue. The problem came from the “Set as Featured Image” setting that could not correctly retrieve the Thumbnail image, since the Post/Thumbnail was never saved before. In fact, for data consistency purpose, the Image field retrieve the Post Thumbnail, and not the ACF metadata when that setting is enabled.

    I will include a fix in the next patch. In the meantime, you can apply the patch by yourself, following these instructions:

    In the file /acf-extended/includes/fields/field-image.php line:147, add the following code:

    if(acf_maybe_get_GET('preview') && filter_var(acf_maybe_get_GET('preview'), FILTER_VALIDATE_BOOLEAN)){
        return $value;
    }

    Final code snippet should look like this:

    if(!acf_maybe_get($field, 'acfe_thumbnail'))
        return $value;
    
    if(acf_maybe_get_GET('preview') && filter_var(acf_maybe_get_GET('preview'), FILTER_VALIDATE_BOOLEAN)){
        return $value;
    }
    
    $data = acf_get_post_id_info($post_id);
    

    Sorry for the inconvenience.

    Have a nice day!

    Regards.

    Thread Starter Chris

    (@pma4life)

    Hi Konrad!

    I can confirm that fix worked. Thank you very much for resolving this as well as all your work on such a great plugin!

    Cheers!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Great to hear!

    If you enjoy this plugin and its support, feel free to submit a review. It always helps and it’s much appreciated ??

    Have a nice day!

    Regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Preview of CPT – ACF image field does not display’ is closed to new replies.