php - Infinite loop in wordpress WP_Query loop -


i have following code, i'm not sure having context of happens within while loop hugely important. issue lies continue; in if statement. condition in if met, , continue; reached. created infinite loop though. can not understand why case though?

could suggest why wordpress can not handle continue; in wp_query loop?

while ($latest_events->have_posts()) {          $id = get_the_id();                      $custom_fields = base_get_all_custom_fields($id);                    $event_type = $custom_fields["course/event_type"][0];          if(isset($event_type) && strpos_arr($event_type, array('training')) !== false ){                 continue;         }            $latest_events->the_post();         get_template_part('partials/latest-espresso-events');     } 

if don't call $latest_event->the_post() loop counter not advanced, therefor have infinite loop.

you must call $latest_event->the_post() before continue; statement make sure go next post (otherwise $latest_events->have_posts() return true).

        if(isset($event_type) && strpos_arr($event_type, array('training')) !== false ){             $latest_event->the_post();             continue;         }   

Comments