Support

Account

Home Forums General Issues Loop in a loop Reply To: Loop in a loop

  • Hi,

    Finally my problem is solved:

    <?php if($orderBy == 'city' ) { ?>
    
                        <?php
                        function getField($title = '') {
                            $options = array();
                            $field_groups = acf_get_field_groups();
                            foreach ( $field_groups as $group ) {
                                $fields = get_posts(array(
                                    'posts_per_page'   => -1,
                                    'post_type'        => 'acf-field',
                                    'orderby'          => 'menu_order',
                                    'order'            => 'ASC',
                                    'suppress_filters' => true,
                                    'post_parent'      => $group['ID'],
                                    'post_status'      => 'any',
                                    'update_post_meta_cache' => false
                                ));
                                foreach ( $fields as $field ) {
                                    if ($title && $title == $field->post_title) {
                                       return $field->post_name;
                                    }
                                    $options[$field->post_name] = $field->post_title;
                                }
                            }
                            return $options;
                        }
                        $field = get_field_object(getField('Ville'));
                        $citylist = $field['choices'];
                        function getCity($fields) {
                            $key = $fields['ville']['value'];
                            $ville = $fields['ville']['choices'][$key];
                            return $ville;
                        }
                        ?>
                        <?php
                          if( $citylist ): ?>
                            <ul class="global-members-list row" id="accordionTeamCity">
                                <?php foreach( $citylist as $key => $city ) : ?>
                                    <li class="col-12">
                                        <h3 class="h3-title"><?php echo $city ?></h3>
                                        <ul class="members-list row">
                                        <?php
                                        $teammember = get_posts(array(
                                            'post_type'   => 'members',
                                            'meta_key'    => 'ville',
                                            'meta_value'  => $key));
    
     
                                        foreach ( $teammember as $post ): $counter++ ?>
                                            <li class="col-12 col-xl-4 member-col <?php if (get_field('biographie_gauche') || get_field('biographie_droite')): ?>clickable<?php endif; ?>" data-toggle="collapse" data-target="#collapse<?php echo $counter; ?>" aria-expanded="true" aria-controls="collapse<?php echo $counter; ?>">
                                                <div class="member-item">
                                                    <?php $ville = getCity(get_field_objects()); ?>
                                                    <?php $photo = get_field('photo'); ?>
                                                    <div class="member-photo" style="background-image:url('<?php echo $photo['sizes']['member-photo']; ?>');"></div>
                                                    <div class="member-intro">
                                                        <h4 class="member-name"><?php the_field('prenom'); ?><br /><?php the_field('nom'); ?></h4>
                                                        <?php $metier = get_field('metier'); ?>
                                                        <p class="member-job"><?php echo implode(', ', $metier); ?></p>
                                                        <?php
                                                            $fieldmetier = get_field_object('metier');
                                                            $valuemetier = $fieldmetier['value'];
                                                            // $metier = $fieldmetier['metier'][ $valuemetier ];
                                                        ?>
                                                        <!-- <p class="member-job"><?php echo $metier; ?></p> -->
                                                        <?php
                                                            $fieldville = get_field_object('ville');
                                                            $valueville = $fieldville['value'];
                                                            $ville = $fieldville['choices'][ $valueville ];
                                                        ?>
                                                        <p class="member-city"><?php echo $ville; ?></p>
                                                    </div>
                                                    <div class="trigger-biography-container">
                                                    <?php if( get_field('biographie_gauche') ): ?>
                                                        <div class="trigger-biography">
                                                            <div class="text"><?php echo $boutonbiographie; ?></div>
                                                            <img class="accordion-arrow" src="<?php bloginfo('template_url'); ?>/images/accordion-down-orange.png" alt="" />
                                                            <img class="accordion-arrow accordion-arrow-top" src="<?php bloginfo('template_url'); ?>/images/accordion-top-white.png" alt="" />
                                                        </div>
                                                    <?php endif; ?>
                                                    </div>
                                                </div>
                                                <div class="member-biography member-biography-collapse row" id="collapse<?php echo $counter; ?>" aria-labelledby="heading<?php echo $counter; ?>" data-parent="#accordionTeamCity">
                                                    <div class="biography-col-left col-12 col-xl-6">
                                                        <?php the_field('biographie_gauche'); ?>
                                                    </div>
                                                    <div class="biography-col-left col-12 col-xl-6">
                                                        <?php the_field('biographie_droite'); ?>
                                                    </div>
                                                </div>
                                            </li>
                                            <?php setup_postdata( $post ); ?>
                                        <?php endforeach;  ?>
                                        </ul>
                                        <?php wp_reset_postdata(); ?>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                            <?php wp_reset_postdata(); ?>
                        <?php endif; ?>
    
                    <?php } ?>