Skip Navigation

[Resolved] hierarchical taxonomy with shortcode [display_post_tax_terms_hierarchical]

This support ticket is created 7 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#578679
hierarchical-taxonomy3.png
hierarchical-taxonomy2.png
hierarchical-taxonomy.png

I enter this code at the bottom of functions.php file od my theme:

/**
 * Display taxonomy terms in hierarchical order.
 *
 * Advised by WP Types - Toolset
 */
function list_hierarchical_terms($atts) {
    global $post;
          
    $taxonomy = $atts['jezyk'];
    $separator = $atts['separator'];
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array( "fields" => "ids" , "orderby" => "term_id") );
              
    if( $terms ) {
        $terms = trim( implode( ',', (array) $terms ), ' ,' );
                        $output = wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms."&hierarchical=1"."&separator=".$separator."&echo=0&style=none&order=DESC");
          
                        $output = substr(trim($output), 0, -1);
                          
                        $str_array = explode($separator, $output);
                        if(isset($str_array) && count($str_array)) {
                                    $str_array_rev = array_reverse( $str_array );
                                    $output = implode($separator,$str_array_rev);
                        }
                          
                        return $output;
          
    }
}
add_shortcode( 'display_post_tax_terms_hierarchical', 'list_hierarchical_terms' );

My custom taxonomy is 'jezyk' (language).

In the Content Template of "tlumacz" (translator) I put in this shortcode:

[display_post_tax_terms_hierarchical taxonomy_name="jezyk" separator="<br>"]

Unfortunately the list of taxonimies 'jezyk' doesn't display.

hidden link

#578805

Hi, there must have been a miscommunication. Your shortcode uses the attribute "taxonomy_name" but your PHP code is looking for the attribute "jezyk". I think you need to change your shortcode like so:

function list_hierarchical_terms($atts) {
    global $post;

    $taxonomy = $atts['taxonomy_name'];
    $separator = $atts['separator'];

Also, if you want to use a line break as the separator, you should write that break tag using a backslash:

[display_post_tax_terms_hierarchical taxonomy_name="jezyk" separator="<br />"]