Skip Navigation

[Resolved] display in elementor template all ancestor taxonomy terms

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 6 replies, has 2 voices.

Last updated by ioannaS 1 year, 2 months ago.

Assisted by: Minesh.

Author
Posts
#2690307

Hello. I am building a real estate website. I have created a hierarchical taxonomy for areas and I want to display the selected area along with all ancestor terms in an Elementor template. I also tried to display the area taxonomy terms in hierarchical order (grandparent > parent > child). I haven't gotten neither one to work.

I followed the directions found here https://toolset.com/forums/topic/display-taxonomys-parent-in-taxonomy-view/ along with other tickets found on toolset.com but I'm clearly doing something wrong. Thank you.

#2690313
Screenshot 2024-04-01 185934.png
Screenshot 2024-04-01 185644.png
Screenshot 2024-04-01 185627.png
Screenshot 2024-04-01 185535.png
Screenshot 2024-04-01 185504.png

I have attached some screenshots showing the custom post type and taxonomy names. They also show the code I added on Toolset and the shortcode I added in the Elementor template. If the custom code doesn't work, I wouldn't mind selecting multiple taxonomy terms per post and having a shortcode displaying all custom taxonomy terms in hierarchical order with " > " as the separator (ie. Attica > southern suburbs > Dafni).

#2690433

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share the problem URL and admin access details and let me review what we can do in this case.

Can you please share test post against which I run a test and share your expected result for a specific post/page?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#2690475

Minesh
Supporter

Languages: English (English )

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

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

function func_show_post_hierarchical_terms($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=none");
          
    }
}
add_shortcode('show_post_terms_hierarchical', 'func_show_post_hierarchical_terms');

And added the shortcode to your Elementor template as given under:
=> hidden link

[show_post_terms_hierarchical taxonomy="area" separator=" > "]

Can you please confirm it works as expected.

#2690500

Thank you! This is exactly what I wanted. I have added some styling to the shortcode.

"
<div style="font-size: 22px; font-family: lato;">[show_post_terms_hierarchical taxonomy="area" separator=" > "]</div>
"

I have also noticed that the separator is displayed after the last taxonomy term. Is there a way to hide it?

#2690503

Minesh
Supporter

Languages: English (English )

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

I've adjusted the shortcode added to "Custom Code" as given under:

function func_show_post_hierarchical_terms($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 ), ' ,' );
      
      $terms = wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none");
        $x = explode(" > ",$terms);
      	array_pop($x);
        $terms = join(" > ",$x);
        
      return $terms;
    }
}
add_shortcode('show_post_terms_hierarchical', 'func_show_post_hierarchical_terms');

Can you please confirm it works as expected now:
- hidden link

#2690553

It's working now! Thank you!