I need to check if current post in the loop has the same category that the next one.
while($query->have_posts()){
$query->the_post();
if(category_of_this_post == category_of_the_next_post) //this
//do something
}
I need to check if current post in the loop has the same category that the next one.
while($query->have_posts()){
$query->the_post();
if(category_of_this_post == category_of_the_next_post) //this
//do something
}
A rough setup is the following.
while ( $query->have_posts() ) : $query->the_post();
$next = $query->posts[ $query->current_post + 1];
$current_categories = get_the_category();
$next_post_categories = get_the_category($next->ID);
if ( /* compare $current_categories $next_post_categories */ ) {
}
endwhile;
wp_reset_postdata(); // always reset
A few things to keep in mind: