Support

Account

Home Forums ACF PRO Conditional if more than 1 image added to gallery?

Solved

Conditional if more than 1 image added to gallery?

  • Is it possible to build a conditional based on if more than one image is added to a gallery?

    Only 1 image added to the gallery = show this.
    ELSE
    More than one image = show this..

    I’m assuming this is more of a PHP question than ACF, but unsure how the gallery bits are stored and not competent enough to build a counter from it.

    Many thanks for any help 🙂

  • You really should check for 3 conditions, no images, 1 image, more than 1 image

    
    $images = get_field(gallery_field);
    // the above will return something
    // other than an array
    // if there are no images
    if (is_array($images)) {
      // at lease 1 image
      if (count($images) == 1) {
        // only 1 image
      } else {
        // more than 1 image
      }
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Conditional if more than 1 image added to gallery?’ is closed to new replies.