Post List by category and under custom taxonomy

Question

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

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
0
, , Julham 4 years 2019-11-06T22:24:34-05:00 0 Answers 59 views 0

Leave an answer

Browse
Browse