Skip Navigation

[Resolved] Display related posts based on taxonomy child term

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

Problem:

What I want to achieve: display primarily related posts of the child taxonomy where the view is inserted AND exclude some categories (I'm using the query for this at the moment). IF no other posts of the Child Taxonomy are available, then display posts of the Parent Taxonomy. IF no posts of the parent Taxonomy are available, then displays posts of the tagged WP Category. IF no other posts exist of the same category where the view is inserted, then display nothing.

Solution:

In your case, you might try custom codes, for example:

https://toolset.com/forums/topic/display-related-posts-based-on-taxonomy-child-term/#post-1758849

Relevant Documentation:

This support ticket is created 3 years, 8 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 20 replies, has 3 voices.

Last updated by JorgeE7101 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1760005

No, there isn't such a way for the system ...
But you can display the same view's shortcode, and setup with different shortcode attribute "offset", for example:
[wpv-view name="my-view"]
...
[wpv-view name="my-view" offset=1]
...
[wpv-view name="my-view" offset=2]
...
[wpv-view name="my-view" offset=3]

See our document:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-view
offset (opt):
'amount of results to skip'

#1760071

Thanks. That works for me.

My final question: In archive pages I would like to display related posts as well, but using the Parent Taxonomy. Is it similar to the Child Post? Do I have to create two new views (Parent and Child)? Which settings should I choose to display accurate results?

In this case the archive pages are only tagged with Continent and Country, no cities or regions.

Thanks.

#1762019

Which archive page are we talking about?
Please elaborate the question with more details, I need to test it in my localhost, thanks

#1762145

In the terms taxonomy archive pages.

For example /viagens/america-do-sul/brasil/

I would like in this case to see related articles of Brazil if they exist or of South America.

(Please hide the link.)

Thanks.

#1762199

Thanks for the details, there isn't such kind of built-in feature within Toolset, it needs custom codes, for example:
1) in term archive page /viagens/america-do-sul/brasil/
you can get current "brasil" term's information with function get_queried_object(),
2) Use above term's information to get related parent term "South America" information:
https://developer.wordpress.org/reference/functions/get_ancestors/

Then get related posts information:
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

#1762205

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.