Support

Account

Home Forums ACF PRO AFC gallery field displays featured Image Reply To: AFC gallery field displays featured Image

  • Hi @peternitras-be

    If you look at the docs for a gallery field, it may help.

    If you need to use a shortcode, here’s how the code should look:

    <?php
    
    // Load value (array of ids).
    $image_ids = get_field('gallery');
    if( $image_ids ) {
    
        // Generate string of ids ("123,456,789").
        $images_string = implode( ',', $image_ids );
    
        // Generate and do shortcode.
        // Note: The following string is split to simply prevent our own website from rendering the gallery shortcode.
        $shortcode = sprintf( '[' . 'gallery ids="%s"]', esc_attr($images_string) );
        echo do_shortcode( $shortcode );
    }