01/06/2016 at 8:42 pm
#360233
Keymaster
@ George
The Connections taxonomy code for categories is very heavily based on the core WordPress code… there’s actually no really easy way of doing this. Basically a custom function would need to be written which would get all the categories for an entry, check each to see if it is an ancestor of category ID:34 and then output the appropriate HTML code. This function should do the trick:
function cn_display_terms_of_parent_term_id( $term_id, $terms ) {
$found = array();
foreach ( $terms as $term ) {
if ( cnTerm::isAncestorOf( $term_id, $term->term_id, 'category' ) ) {
$found[] = $term->term_id;
}
}
foreach ( $found as $id ) {
$category = cnTerm::get( $id, 'category' );
if ( ! is_wp_error( $category ) ) {
echo esc_html( $category->name );
} elseif ( is_a( $category, 'WP_Error' ) ) {
echo $category->get_error_message();
}
}
}
You would use it in the card-single.php file like this:
cn_display_terms_of_parent_term_id( 34, $entry->getCategory() );
That should output only the categories that were assigned to an entry with the parent ID of 34.
