1
votes

I’m following this tutorial

https://sridharkatakam.com/custom-wordpress-widget-showing-cpt-entries-categorycategories/

I have two custom taxonomies (events / centers), with their respective child taxonomies ( event1, event2… / center1, center2…).

What should I change to display posts from the same child taxonomy as the current post? (One post can use one eventschild taxonomy, a centers child taxonomy, or both.)

I just want it to match the taxonomy, i don’t use any category.

What i have to use instead of these?

get_the_category()
category_nicename

Don’t mind if is using this method

https://sridharkatakam.com/show-posts-category-current-post/

Very appreciate any help!

1

1 Answers

1
votes
<?php

//first get the current term
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

//then set the args for wp_list_categories
 $args = array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 1,
    'title_li' => ''
 );
 wp_list_categories( $args );
?>

^^This is how I did it donkey's years ago :)