Support

Account

Home Forums ACF PRO How to see $image[\'label\'] from \"choice field\" in gallery images Reply To: How to see $image[\'label\'] from \"choice field\" in gallery images

  • Hello,

    Sorry for my English and my code 🙂

    This page is an ACF image gallery.

    Each image has a “custom field” which corresponds to one of the “multiple choices” of the “custom field”: “essays”

    The “multiple choice” in wordpress is in this form:

    choice_1 : Choice 1
    choice_2 : Choice 2

    There are “checkboxes” at the top of the page that allow you to show or hide groups of images with the same choice.

    Then under each image there is his “choice” which is displayed.

    But strangely <?php the_field(‘essays’, $image[‘ID’]); ?> this code displays: “choice_1”

    I would like it to display “Choice 1” (it will be different for each image group)

    Thanks a lot

    Here is the code for the page :

    
    <script type="text/javascript">
        $(document).ready(function() {
    
            $('input[type="checkbox"]').click(function() {
                var inputValue = $(this).attr("value");
                $("." + inputValue).toggle();
            });
    
            $('select[type="option"]').click(function() {
                var inputValue = $(this).attr("value");
                $("." + inputValue).toggle();
            });
    
        });
    </script>
    
    <div class="tools">
        <div class="essays">
            <div class="coche">
                <?php
                $field2 = get_field_object('essays');
                if ($field2['choices']) : ?>
                    <?php foreach ($field2['choices'] as $value => $label2) : ?>
                        <label class="lab"><input type="checkbox" checked="checked" name="colorCheckbox" value="voir-essays-<?php echo $value; ?>"><?php echo $label2; ?> </label>
                    <?php endforeach; ?>
                <?php endif; ?>
            </div>
        </div>
    </div>
    
    <div class="tools-player">
    
        <div class="embed-container">
            <?php
            $args = array(
                'post_type' => 'post',
                'post_status' => 'publish',
                'posts_per_page' => -1,
                'orderby' => 'title',
                'order' => 'ASC',
            );
    
            $loop = new WP_Query($args);
    
            while ($loop->have_posts()) : $loop->the_post();
            endwhile;
            wp_reset_postdata();
            ?>
    
            <?php
            while (have_posts()) : the_post();
            ?>
        </div>
    </div>
    
    <main id="primary" class="site-main">
    
        <div id="scroll">
            <div id="scroll2">
    
                <?php
                $images = get_field('gallery');
    
                if ($images) : ?>
                    <div>
                        <?php foreach ($images as $image) : ?>
    
                            <?php $field = get_field_object('essays'); ?>
    
                            <div class="photo-bloc thumbnail-item2 voir-commissions-<?php the_field('commissions', $image['ID']); ?> voir-essays-<?php the_field('essays', $image['ID']); ?>  ">
    
                                <img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
    
                                <div class="tooltip">
                                    <p>
                                        <?php the_field('essays', $image['ID']);  ?>
     <!-- HERE I WOULD LIKE TO HAVE THE LABEL "CHOICE 1" and not "choix_1" (which is displayed instead of ID) -->
    
                                    </p>
    
                                    <p><?php echo $image['caption']; ?></p>
                                </div>
    
                            </div>
    
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
    
            <?php
            endwhile; // End of the loop.
            ?>
    
            </div>
        </div>
        </div>
    </main><!-- #main -->

    Thanks a lot