Skip Navigation

[Resolved] Display parent term name and link

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.

Our next available supporter will start replying to tickets in about 0.48 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by deanL 5 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#1226638

When users are looking at child term archive page, I want to allow them to go back to parent term archive page. For eg, From "China", user can navigate to "Asia".

I used the code from this page:
https://toolset.com/forums/topic/display-link-to-parent-term/

But on frontend I ended up with error message:
Notice: Undefined index: taxonomy in /www/wp-content/themes/travelscams/functions.php on line 116 Notice: Trying to get property of non-object in /www/wp-content/themes/travelscams/functions.php on line 120
' type="category"]

See: hidden link

What am I missing here?

#1226660

Well, it seems that code does not work, see the next reply on the same thread:
https://toolset.com/forums/topic/display-link-to-parent-term/#post-1120938

This here https://toolset.com/forums/topic/display-link-to-parent-term/#post-1120640 shows also that the code is faulty, but the user did not enable WP Debug like you, hence, he sees nothing, instead of the error.

That user was able to solve the problem with this code https://toolset.com/forums/topic/how-to-set-condition-on-filter-controls/ but I think it's not what you want.

Your request is to "get" the parent term, so to put it as a link to the current (child) archive page.
You cannot do that in Toolset.

I mean, you could set up Views that list only terms with no parent and terms with parents as in (parent view, archive or etc), but that is also not helping you to get closer to your goal.
Hence again Nigel's code should help to get started, as it does exactly that.
It gets the current term and then returns its parent.
There are also core functions of WordPress that help you achieve that:
https://codex.wordpress.org/Function_Reference/get_ancestors
That should work both on Post Types and Taxonomies.
Or, https://developer.wordpress.org/reference/functions/get_term_parents_list/, which is tailored for taxonomies only.
That can then be returned in a Custom ShortCode and wrapped to an HREF link.
This would then allow producing such "parent" links on child term archives as you mention, but it falls under Custom Code that we cannot produce in a ready to go state.
We can, however, help to review where issues pop up or give ideas like above.

Please let me know if you need more details or struggle with the implementation.

#1226694

Thank you Beda for your response. I guess I will have to look for alternative ways to do this. Meanwhile we may close this ticket.