Home › Forums › Front-end Issues › WP_query for each loop › Reply To: WP_query for each loop
What you need to do is look at the value for wheel_section and compare it to the value of the last post to see if you need to start a new group
if (have_posts()) {
$last_wheel_section = '';
while(have_posts()) {
the_post();
$this_wheel_section = get_field('wheel_section');
if ($this_wheel_section != $last_wheel_section) {
// new section started
// this will always be true for the first section
}
// other code for each wheel section
// at end of loop set $last_wheel_section to $this_wheel_section
$last_wheel_section = $this_wheel_section
} // end whild have_posts
} // end if have_posts
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.