I want to show child categories list on parent taxonomy which I almost obtained using wp_list_categories

The problem is I want to show my custom post type of the last child category when I reach last child Category.


Got some ideas for your requirement. Check below code...

$child = get_categories('child_of='.$parent. '&hide_empty=0&echo=0&taxonomy=custom_taxonomy');
     foreach ( $child as $row ) { $i++;
        echo '<li><a href="'.get_term_link($row,$row->taxonomy).'">'.$row->name.'</a></li>';
            $args=array( 'post_type' => 'custom_post','order' => 'DESC', 'posts_per_page'=>1,'tax_query'  => array( array('taxonomy' => 'custom_taxonomy','terms' =>$row->term_id, 'field' => 'id' )) );
            $second_query = new WP_Query( $args );
                if ($second_query->have_posts()) :
                    while ($second_query->have_posts()) : $second_query->the_post();
                        echo get_the_title();
                endif; wp_reset_query();
  • 2
    Txs for ur code. I sure try this. – Ashish Feb 8 '16 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.