Display Parent and Sub Categories on Single CPT View

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.

Hello @MulderDSM,

Thank you for the very detailed post information. To be able to resolve your issue, please check out this thread instead:

Best Regards.

Thank you! From this I was able to tweak the snippets and loopers to get closer. I am now able to pull the selected 2 parents back (one per column) but the children that I pull back represent all child/sub categories, not just the ones selected.

Hello @MulderDSM,

The Custom Looper Provider parentcat should only return the current post parent terms so that you can used these terms for the subcat. You might need to use get_the_termshttps://developer.wordpress.org/reference/functions/get_the_terms/ function.

Be advised that this is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.