Skip Navigation

[Resolved] Hierarchical taxonomy order

This thread is resolved. Here is a description of the problem and solution.

Problem:

I used code from here https://toolset.com/forums/topic/taxonomy-order-2/#post-526921. It worked well but I also need to show the taxonomy in link format at a place. I tried passing format link but it didnt work.

Solution:

You can try to modify the PHP codes as below:

https://toolset.com/forums/topic/hierarchical-taxonomy-order/#post-1221438

Relevant Documentation:

This support ticket is created 5 years, 7 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Sasank 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1221076

I want to show taxonomy in hierarchical order.

I used code from here https://toolset.com/forums/topic/taxonomy-order-2/#post-526921. It worked well but I also need to show the taxonomy in link format at a place. I tried passing format link but it didnt work.

Where can I find the parameters that can be passed? and how do I have option for name or link output?

Wish Toolset had option to display in hierarchical order instead of just Ascending or Descending by name.

Regards,
Sasank

#1221360
child-filters.JPG
parent-filters.JPG

Hello,

It does not need custom codes, you can setup a nested view for it.

For example, in a single post content,
1) Create a taxonomy view "parent-view":
- Query terms of your custom taxonomy
- filter by:
a) Select taxonomy terms whose parent is None.
b) Taxonomy is set by the page where this View is inserted
See screenshot: parent-filters.JPG
- in section "Loop Editor", within shortcode <wpv-loop>.. </wpv-loop>
display term's link shortcode [wpv-taxonomy-link] + below child view's shortcode

2) Create a taxonomy view "child-view":
- Query terms of your custom taxonomy
- filter by:
a) Select taxonomy terms whose parent is the value set by the parent view.
b) Taxonomy is set by the page where this View is inserted
See screenshot: child-filters.JPG
- in section "Loop Editor", within shortcode <wpv-loop>.. </wpv-loop>
display term's link shortcode [wpv-taxonomy-link]

You can also format both parent and child views by following our document:
https://toolset.com/documentation/user-guides/view-layouts-101/#the-output-formats

#1221394

Hi,

Thank you for your reply.

The solution you gave seems to complicate things a bit going forward. The code mentioned here https://toolset.com/forums/topic/taxonomy-order-2/#post-526921 totally works as needed just that in someplace I want with link and other I want with link.

Can you point me towards how to modify it? I am not good at php and guess this is more of php to what I understood after searching a bit...

Regards,
Sasank

#1221438

You can try to modify the PHP codes as below:

function list_hierarchical_terms($atts) {
	$taxonomy = 'category'; // change this to your taxonomy
	$separator = ', ';
	$terms = wp_get_object_terms( get_the_ID(), $taxonomy, array( 'orderby' => 'term_id', 'order' => 'ASC', 'fields' => 'all') );
	if ( is_wp_error( $terms ) || empty( $terms ) ) {
		return;
	}
	
	$arr = array();
	foreach( $terms as $term ) {
		$arr[] = '<a href="' . get_term_link($term->term_id) . '">' . $term->name . '</a>';
	}
	return implode($separator, $arr); 
}
add_shortcode('display_post_tax_terms_hierarchical', 'list_hierarchical_terms');

And test again

#1223137

My issue is resolved now. Thank you!