Support

Account

Home Forums Add-ons Gallery Field If gallery is not populated, it pulls media inserted into Post.

Solved

If gallery is not populated, it pulls media inserted into Post.

  • Im using the gallery add on to generate basic WP galleries. It works great if theres media put into the ACF gallery. But if nothing is entered it automatically starts pulling media thats been inserted into a post.

    You can see an example here, in this example the only media is the flyer as media within the post itself, but its automatically building a gallery with it:
    http://xeroproject.com/lorizimmer/rock-paper-scissors/

    The code I’m using is:

    $image_ids = get_field('gallery', false, false);														
    $shortcode = '[gallery class="fancybox" link="file" columns="4" ids="' . implode(',', (array)$image_ids) . '"]';
    echo do_shortcode( $shortcode );
    ?>
  • Only do the shortcode if the gallery field has a value, otherwise the WP gallery shortcode is doing what is should be doing when no ids are supplied

    
    $image_ids = get_field('gallery', false, false);
    if (!empty($image_ids)) {
      $shortcode = '[gallery class="fancybox" link="file" columns="4" ids="' . 
                    implode(',', (array)$image_ids) . '"]';
      echo do_shortcode( $shortcode );
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘If gallery is not populated, it pulls media inserted into Post.’ is closed to new replies.