Home › Forums › General Issues › Multiple/nested query in a single loop › Reply To: Multiple/nested query in a single loop
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 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.