Support

Account

Home Forums Add-ons Repeater Field Query repeater field with two values Reply To: Query repeater field with two values

  • Hi John,

    Thank you for your replies. Despite several tests, i can’t do it. Have you a concrete example of the second method ?

    Also, I have tweaked something to arrive where i want but the problem is that if the choice is not checked its value appears anyway even if there are no posts related. The result is :

    DATE 1 (taxonomy)

    Location 1 (taxonomy)
    Film A
    Film B

    Location 2
    Film B
    Film C

    Location 3

    If Location 3 is empty, i don’t want to display it…

    I think your method is best than mine 😉

        <?php // CHAMPS LIEUX
    
        $jours_key = "field_5886014c7f9f1";
        $jours = get_field_object($jours_key);
    
        foreach($jours['choices'] as $k => $v) : 
    
        $lieux_key = "field_5880dc1d1f784";
        $lieux = get_field_object($lieux_key); 
    
        ?>
    
        <h3><?php echo $v; ?></h3>
    
        <?php foreach($lieux['choices'] as $cle => $valeur) :
    
        $args = array(
            'post_type'     => 'film',
            'meta_query'    => array(
                'relation'      => 'AND',
                array(
                    'key'       => 'seances_%_jour2',
                    'compare'   => 'LIKE',
                    'value'     => $k,
                )
            )
        );
        $the_query = new WP_Query( $args ); ?> 
    
        <h3 style="color:#ccc"><?php echo $valeur; ?></h3>
      
        <?php if($the_query->have_posts()) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
                <?php if( have_rows('seances') ): while( have_rows('seances') ): the_row(); 
                    $date = get_sub_field('jour2');
                    $lieux = get_sub_field('lieu');
                    $horaire = get_sub_field('horaire'); ?>
    
                    <?php if ($date['label'] == $v && $lieux['label'] == $valeur) : ?>
                        <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
                        <p><?php echo $horaire; ?></p>
                    <?php endif; ?>
    
                <?php endwhile; endif; ?>
    
        <?php endwhile; endif;  wp_reset_postdata(); ?>
    
        <?php endforeach; ?>
        <?php endforeach; ?>