Home Forums Add-ons Flexible Content Field Featured Image Included in Gallery in Flexible Content Field


Featured Image Included in Gallery in Flexible Content Field

  • Hi,

    I’ve got a flexible content field that has a gallery sub-field. On the post where the flexible content field is being rendered, I have also specified a featured image.

    I am rendering the gallery sub-field as a WP gallery using a shortcode. I have added three images to the gallery (none of which are the featured image). For some reason, the featured image is being included in the gallery.

    Here is the relevant code:

    // display gallery as wp gallery
                    echo '<h3>Movie Image Gallery</h3>';
                    $stills_array = array();
                    while (have_rows('movie_stills')) {
                        $still = get_sub_field('movie_stills');
                        $stills_array[] = $still['id'];
                    $shortcode = '[gallery ids="' . implode(',', $stills_array) . '"]';
                    echo do_shortcode($shortcode);

    Any idea why this is being included? How/Why is it being included when I loop through the sub-field?


  • I think you may be using the wrong code to get and display the gallery. See the “Create WP Gallery” section of this page

    In your case you should probably be using something like:

    $image_ids = get_sub_field('movie_stills', false, false);
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]'
    echo do_shortcode( $shortcode );
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.