Support

Account

Home Forums General Issues Multiple/nested query in a single loop Reply To: Multiple/nested query in a single loop

  • Hi @sonnenschauer

    I believe you posted the scripts as separate posts with the same post title. I’m afraid this is more of a PHP and WP issue than ACF issue. For something like this, I suggest you ask to PHP or WP community instead. But, I have created an example logic for this situation:

    <?php
    if ( $custom_query->have_posts() ) :
    
        $current_video_number = false;
        $current_topic = false;
        $current_timestamp = false;
        $current_chosen = false;
        
        while ( $custom_query->have_posts() ) : $custom_query->the_post();
        
            $temp_video_number = get_field('video_number');
            $temp_topic = get_field('topic');
            $temp_timestamp = get_field('timestamp');
            $temp_chosen = get_field('chosen');
            
            if( !$current_video_number ){
                $current_video_number = $temp_video_number;
                $current_topic = $temp_topic;
                $current_timestamp = $temp_timestamp;
                $current_chosen = $temp_chosen;
            } elseif ( $current_video_number == $temp_video_number ) {
                $current_timestamp = $temp_timestamp;
                if( $temp_chosen == 'Yes' || ($current_chosen == 'No' && $temp_chosen == 'Yes') ) {
                    $current_chosen = 'Yes';
                } else {
                    $current_chosen = 'No';
                }
            } else {
                echo $current_video_number;
                echo $current_topic;
                echo $current_timestamp;
                echo $current_chosen;
                
                $current_video_number = $temp_video_number;
                $current_topic = $temp_topic;
                $current_timestamp = $temp_timestamp;
                $current_chosen = $temp_chosen;
            }
    
        endwhile;
        
    endif;
    wp_reset_postdata(); ?>

    If you need further support, please consult with PHP or WordPress community instead.

    Thanks 🙂