Just switch conditionally. The rewind_posts()
function allows you to loop through the same loop a second time, while the has_term()
function allows you to check if the currently looped post has a specific term of a specific taxonomy.
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
if ( ! has_term( 'term_A_slug/term_A_id', 'taxonomy' ) )
continue;
// display post here
}
}
rewind_posts();
// Second loop
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
if ( ! has_term( 'term_B_slug/term_B_id', 'taxonomy' ) )
continue;
// display post here
}
}