Support

Account

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