Support

Account

Home Forums Add-ons Flexible Content Field Gallery with Flexible Content

Solved

Gallery with Flexible Content

  • Hi

    I purchased Gallery and Flexible Content plugin and juts tried to let them work together but if I use this code `<?php

    $image_ids = get_sub_field(‘gallery’, false, false);

    $shortcode = ‘
    [gallery ids="' . implode(',', $image_ids) . '"]
    ‘;

    echo do_shortcode( $shortcode );

    ?>`
    it does not work.
    I changed get_field to get_sub_field but I only get [gallery ids="Array,Array,Array"]

    What do I have to change to get it working?

    Best regards Matthias

  • Hi @Matthias

    The get_sub_field does not have an option for formatting.

    You will need to construct the $ids like so:

    
    <?php 
    
    $images = get_sub_field('gallery');
    $image_ids = array();
    
    foreach( $images as $image )
    {
    	$image_ids[] = $image['id'];
    }
    
    $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';
    
    echo do_shortcode( $shortcode );
    
    ?>
    
  • Elliot – thank you, thank you, thank you! I was trying to use the Gallery plugin with the Repeater plugin and I was having the same problem. I couldn’t figure out why the original WP Gallery code example wouldn’t work with get_sub_field.

    It took me quite a while to find this thread. As a suggestion, you might consider putting this code example in either the Gallery or Repeater documentation (or both).

    Thanks!

  • Hi @Paul

    This code is already in the gallery field documentation down the bottom!

    Thanks
    E

  • Hi @elliot

    The original code that Matthias and I both tried to use is at the bottom of the gallery field documentation, but I couldn’t find your revised code to use a gallery sub_field anywhere but on this thread. That’s the code I think it would be helpful to post in the documentation. Did I miss it?

    Thanks,

    paul

  • Hi @elliot

    I used the code that you posted in your original reply exactly as you wrote it, with the exception that I changed

    echo do_shortcode( $shortcode );

    to

    echo apply_filters('the_content', $shortcode);

    It seems to be working fine, but some of this is a little over my head so I wanted to get your opinion. Do you think there’s any problems with using apply_filters instead of do_shortcode? Will this require more processing and potentially slow down the page?

    I made this switch because I’m trying to use a plugin called Simple Light Box, and it won’t work if the gallery isn’t run though the the_content filter.

    Thanks,

    paul

  • Hi there,

    Confirming that this solution worked for me as well, but I’m not seeing it in the Gallery documentation as was indicated earlier in this thread.

    http://www.advancedcustomfields.com/resources/field-types/gallery/

    Perhaps it’s in another location, or could it be added?

    Thanks for your help!

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Gallery with Flexible Content’ is closed to new replies.