Skip Navigation

[Resolved] Display hierarchical data (parent – child) for taxonomy field

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 2 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2384991
need-to-do.jpg
before.jpg

Hello,

I'm developing some improvements for my licensed site and I'm struggling to display the values of a hierarchical taxonomy field.

I have a field with hierarchical taxonomies called Type of Administrative Action. Only 2 levels, parent and child.

Right now the way it is working on my website (see attached image) it is displaying all the values in alphabetical order ignoring the hierarchy.

But I want to display it like a parent - child grouped together. Please see the second screenshot that is mockup of how I would like it to be displayed.

I had a look for the short code and some ideas in the forums like this one. https://toolset.com/forums/topic/display-wpv-post-taxonomy-and-hierarchical-taxonomies/ But without luck.

Any help would appreciated.

Thank you in advance.

#2385221

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The shortcode I shared with the reference ticket should work. I'm not sure how exactly you added the shortcode.

Could you please share problem URL where you want to display the hierarchical terms as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2385449

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now:
- hidden link

I've added the following custom shortcode to "Custom Code" section offered by Toolset:
=> hidden link

function func_list_hierarchical_terms_single($atts) {
    global $post;
            
    $taxonomy = $atts['taxonomy']; 
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
        return wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=list");
           
    }
}
add_shortcode('show_tax_terms_hierarchical', 'func_list_hierarchical_terms_single');

Then, I've displayed the above shortcode using "Fields and Text" block within your content template:
=> hidden link

[show_tax_terms_hierarchical taxonomy="administrative-action" separator=""] 

I've added the following CSS code to style the hierarchical list to the content template's CSS box:

ul.children li {

    padding: 0 10px;
list-style:none;
border-left:1px solid black;
}

.tb-fields-and-text li {
list-style:none;
}

Can you please confirm it works as expected now..