Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Use wp_list_categories to navigate through custom taxonomy to custom post type Re: Use wp_list_categories to navigate through custom taxonomy to custom post type

#141545
andymacleod
Participant

$term_slug = get_query_var( ‘term’ );
$taxonomy_name = get_query_var( ‘taxonomy’ );
$current_term = get_term_by( ‘slug’, $term_slug, $taxonomy_name );
$args_cats = array(
‘taxonomy’ => $taxonomy_name,
‘hierarchical’ => true,
‘child_of’ => $current_term->term_id,
‘depth’ => ‘1’,
‘hide_empty’ => ‘0’,
‘title_li’ => ”,
‘echo’ => ‘0’,
);
$args_children = array(
‘parent’ => $current_term->term_id,
‘hide_empty’ => false
);
$children = get_terms( $current_term->taxonomy, $args_children);
// print_r($children); // uncomment to examine for debugging
if($children) { // get_terms will return false if tax does not exist or term wasn’t found.
echo wp_list_categories($args_cats);
} else {
$args_lessons = array(
‘child_of’ => $wp_query->tax_query->queries[0],
‘title_li’ => ”,
‘post_type’ => ‘lessons’
);
wp_list_pages($args_lessons);
}

?>