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?
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.
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.