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
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 />"]