This is quite simple to implement. Get all taxonomies via get_terms()
and get the related posts with a custom WP_Query
and tax_query
.
// get all terms
$terms = get_terms( 'docs_category', array(
'hide_empty' => true,
'parent' => 0,
) );
if( !empty( $terms ) && !is_wp_error( $terms ) ):
foreach ( $terms as $term ):
// fetch current term_id
$current_term_id = $term->term_id;
// get posts by term_id
$args = array(
'post_type' => 'docs',
'post_status' => 'publish',
'posts_per_page' => 3,
'tax_query' => array(
array(
'taxonomy' => 'docs_category',
'field' => 'term_id', // Or 'term_id' or 'name'
'terms' => $term->term_id, // A slug term
'operator' => 'IN',
)
)
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while($the_query->have_posts()): the_post();
// Do your stuff here...
endwhile;
wp_reset_postdata();
endif;
endforeach;
endif;
Edit: Sorry i skipped the topic with the posts without taxonomy. But you certaintly get a feel for how it works. You could create another WP_Query and an array of all available taxonomies and use a tax_query with an operator ‘NOT IN’.