Wordpress Custom Post category archive -


i have custom post type set up, number of categories , sub categories.

what trying create page shows posts in specific category, menu lists category sub categories posts can filtered.

i have tried copying archive template , renaming taxonomy-(my-custom-taxonomy).php if go slug shows posts, , using <?php wp_list_categories(); ?> want list of sub-categories of specific category, , filter posts. struggling show these , use 1 template categories , children.

you can use

$term_id = get_queried_object()->term_id; 

and

$tax= get_query_var( 'taxonomy' )  

to return details of current term , taxonomy being viewed in taxonomy.php page.

you can use info get_term_children child terms of current term being displayed. examples, see link provided

edit

your code should this

<?php $term_id = get_queried_object()->term_id; $taxonomy_name = get_query_var( 'taxonomy' );  $termchildren = get_term_children( $term_id, $taxonomy_name );  foreach ( $termchildren $child ) {     echo '<ul>';         $term = get_term_by( 'id', $child, $taxonomy_name );         echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';      $args = array(         'tax_query' => array(             array(                 'taxonomy' => $taxonomy_name,                 'field'    => 'slug',                 'terms'    => $term->slug,             ),         ),     );     $the_query = new wp_query( $args );      while ( $the_query->have_posts() ) {         $the_query->the_post();         echo '<p>' . get_the_title() . '</p>';     }     wp_reset_postdata();      echo '</ul>';     } ?>  

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -