Skip to main content

Not a particularly elegant solution but you can create multiple queries each for the specific terms and then output them. Hopefully someone can come up with a nicer way of automatically pulling the terms to modify the output/sorting. But this would get you going.

<?php

//First Query for Posts matching term1
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term1' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $wp_query$query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}

//RESET YOUR QUERY VARS
wp_reset_query();

//Second Query for term2
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term2' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $wp_query$query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}

Not a particularly elegant solution but you can create multiple queries each for the specific terms and then output them. Hopefully someone can come up with a nicer way of automatically pulling the terms to modify the output/sorting. But this would get you going.

<?php

//First Query for Posts matching term1
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term1' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $wp_query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}

//RESET YOUR QUERY VARS
wp_reset_query();

//Second Query for term2
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term2' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $wp_query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}

Not a particularly elegant solution but you can create multiple queries each for the specific terms and then output them. Hopefully someone can come up with a nicer way of automatically pulling the terms to modify the output/sorting. But this would get you going.

<?php

//First Query for Posts matching term1
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term1' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}

//RESET YOUR QUERY VARS
wp_reset_query();

//Second Query for term2
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term2' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}
Source Link

Not a particularly elegant solution but you can create multiple queries each for the specific terms and then output them. Hopefully someone can come up with a nicer way of automatically pulling the terms to modify the output/sorting. But this would get you going.

<?php

//First Query for Posts matching term1
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term1' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $wp_query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}

//RESET YOUR QUERY VARS
wp_reset_query();

//Second Query for term2
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'taxonomy_1',
            'field' => 'slug',
            'terms' => array( 'term2' )
        ),
    ),
    'post_type' => 'my-post-type'
);
$query = new WP_Query( $args );

if ( have_posts() ) {
    
    $term = $wp_query->queried_object;
    
    echo 'All posts found in ' . $term->name;
    
    while ( have_posts() ) : the_post();
        //Output what you want
        the_title();
        the_content();
    endwhile;
}