Post List by category and under custom taxonomy

I am trying to listing posts from a single category with custom taxonomy and several sub custom taxonomy.

sub custom taxonomy “Knowledgebase”

post KB 1
post KB 2

sub custom taxonomy “Optimization “

post OP 1

but result is repeat post list not by custom taxonomy:

sub custom taxonomy “Knowledgebase”

post KB 1
post KB 2
post OP 1

sub custom taxonomy “Optimization”

post KB 1
post KB 2
post OP 1

eg. code:

$taxonomies = get_terms(
array(
‘taxonomy’ => ‘tutorial’,
‘hide_empty’ => false,
)
);

// Loop through categories
foreach ( $taxonomies as $taxonomy ) {

// Display Taxonomy name
echo ‘<h2 class=”post-title”>’ . $taxonomy->name . ‘</h2>’;
echo ‘<div class=”post-list”>’;

// WP_Query arguments
$args = array(
‘cat’ => 2, // wordpress category
‘terms’ => name,
‘orderby’ => ‘term_order’,
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<p><a href=”<?php the_permalink();?>”><?php the_title(); ?></a></p>
<?php

Read more here:: Post List by category and under custom taxonomy

Leave a Reply

Your email address will not be published. Required fields are marked *