So from the parent taxonomy view:

  • Child 1

    • post
    • post
    • post
  • Child 2

    • post
    • post
    • post
    • post
  • Child 3

    • post
    • post
    • post
    • post

I’ve scoured the internet for a solution to this, but nothing seems to be working. I’m able to successfully echo the term ID, but when I pass that into the query it returns nothing.

<?php
    $terms = get_terms( 'ht_kb_category' );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
        echo '<ul>';
        foreach ( $terms as $term ) {
            if ($term->parent != 0) {
                echo '<li><h1>' . $term->name . '</h1></li>';

                $the_query = new WP_Query( array(
                    'post_type' => 'post',
                    'tax_query' => array(
                        array (
                            'taxonomy' => 'ht_kb_category',
                            'field' => 'slug',
                            'terms' => $term->slug,
                        )
                    ),
                ) );

                while ( $the_query->have_posts() ) :

                echo '<p>'. the_title() .'</p>';

                endwhile;

                /* Restore original Post Data
                 * NB: Because we are using new WP_Query we aren't stomping on the
                 * original $wp_query and it does not need to be reset.
                */
                wp_reset_postdata();

            }
        }
        echo '</ul>';
    } ?>

Read more here: Retrieve posts by custom taxonomy child on parent taxonomy page


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: