Custom Order Posts by Category Taxonomy

I’m trying to find a way to organize recent posts based on taxonomy. Meaning:

First: taxonomy name 1 (3 posts)
Second: taxonomy name 2 (3 posts)…and so on.

I’ve read in many posts that it can’t really be done unless I use a plugin or shortcode, which isn’t an option.

Thank you.

Hi, @toad78. I’m pretty sure it can be done with a little creative PHP coding. If you don’t get anyone else able to help you out here, I can work on it a bit later today. Unfortunately right now I am tied up.

Thank you, WebMachine, for your response and willingness to help.

I’ve managed to create my own override. However, the order is not correct. I wanted the posts to be in order by the category ID then by date in descending order. Meaning 5 (Wellness), 3 (Food), 2 (Fitness). The results seem rather scattered.

/* CUSTOM POST OVERRIDE TO DISPLAY POSTS FROM THREE SPECIFIC CATEGORIES, THREE POSTS EACH, SORTED IN DESCENDING ORDER BY DATE */

<?php query_posts( array ( 'category__in' => array(5,3,2), 'posts_per_page' => 3, 'orderby' => 'date', 'order' => 'DESC' ) ); ?>

Try changing your orderby to

  'orderby' => array( 
        'category_id' => 'ASC',
        'date' => 'DESC',
    )

Thanks, @WebMachine. I did what you suggested but still seeing some ‘out of order’ categories:

<?php query_posts( array ( 'category__in' => array(5,3,2), 'posts_per_page' => 12, 'orderby' => array ( 'category_id' => 'ASC', 'date' => 'DESC' ) ) ); ?>
<?php if ( have_posts() ) : ?>
	<div class="grid c">
		<?php

		/* Start the Loop */
		while ( have_posts() ) :
			the_post();
			?>

			<div class="grid__col grid__col--1-of-2">

				<?php get_template_part( 'template-parts/excerpt2', brimstone_get_page_template_in_loop() ); ?>

			</div>

		<?php endwhile; ?>
	</div>
<?php endif; ?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.