Support

Account

Home Forums Add-ons Gallery Field Display all the unique value of a field

Solved

Display all the unique value of a field

  • Hello,
    I want to display all unique values ​​of a “photographer” field of each media in the gallery.
    Without repeating the same value if it already exists.
    Example of photographer present in the select “photographer” field of ACF in the gallery:
    Photographer 1
    Photographer 2
    Photographer 3.
    I want to display:
    Photographer 1
    Photographer 2
    Photographer 3.
    and not the same value repeated.

    Thanks a lot for the help.

    here is my code:

      <div class="photographe">
          
        <?php $images = get_field('gallery'); ?>
    
            <?php if ($images) : ?>
              
                    <?php foreach ($images as $image) : ?>
        
        <label><input type="checkbox" checked="checked" name="colorCheckbox" value="<?php the_field('photographe', $image['ID']); ?>"> <?php the_field('photographe', $image['ID']); ?> </label>
        <?php
    
    ?>                
                    <?php endforeach; ?>
            <?php endif; ?>
        </div>
  • <?php
    $field = get_field_object('my_select');
    if( $field['choices'] ): ?>
        <ul>
            <?php foreach( $field['choices'] as $value => $label ): ?>
                <li><?php echo $label; ?></li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.