I have a single post layout for a CPT called “artist”. I have a taxonomy called “artist-discipline” that accepts parent and children(sub) categories.
When displaying the single post view for the CPT, I need to display these where they appear related, for example:
Dance: Ballroom, General, Hip Hop, Jazz
Design: General, Graphic
Here is a mock-up post on my development server: https://wordpress-126964-3439916.cloudwaysapps.com/artist/test-one/
I’ve created two snippets running also based on research on this site. This first one is for getting the parent category with loopers
/**
* Get parent category with Loopers
*/
add_filter('cs_looper_custom_parentcat', function($result, $args)
{
$category = get_queried_object();
$cat_args = array(
'hide_empty' => 1,
'parent' => 0,
'taxonomy' => 'artist-discipline'
);
$parentcats = get_categories($cat_args);
return $parentcats;
}, 10, 2);
This one to get children.
/**
* Get sub category with Loopers
*/
add_filter('cs_looper_custom_subcat', function($result, $args) {
$cat_args = get_categories(array(
'taxonomy'=> 'artist-discipline',
'hide_empty'=> 1,
'parent'=> get_queried_object_id(),
'orderby' => 'name',
'order' => 'ASC'
));
return $cat_args;
}, 10, 2);
I will provide credentials in secure note.