[Resuelto] Query Filter to display only related child posts?
This support ticket is created hace 7 años. 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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Where you say "related child posts" that sounds like you have set up parent-child post relationships and when viewing a child post you want to display siblings (i.e. other children of the same parent post).
But then you say "with the same child category", which sounds like something else.
At the bottom of that post I am trying to display 4 Ashtray posts, 2x2 with a "more" button leading to ashtray archives. The site consists of a few parent categories and each parent has multiple children. I'm trying to create one view/template that will display posts related to the child category.
This may not something you can readily do in Toolset without writing custom code. The problem is that when getting the categories of a post there is no distinction made about the position of the category in any hierarchy (https://developer.wordpress.org/reference/functions/get_the_category/).
I assume that for this example post it has both the cigar and the ashtray categories, yes? enlace oculto
You can create a View that you display on the same post which has a Query Filter to display posts with categories the same as the post where it is displayed (see screenshot).
But the current post with that example has the categories "cigar" and "ashtray". So the View will find posts that have categories "cigar" or "ashtray".
I assume you want it to only show other posts that have the "ashtray" category.
If you want that then you will need to code a custom solution.
If your related posts can be any other cigar-related post then the above will work for you.
I came up with the following code example for you.
You will need to edit the View ID.
Please note that providing custom code is outside of our support policy and this is intended to help you get started if the code needs modifying in any way.
The intended use is that you insert a View for related posts which has a Query Filter to display posts within the same category as the current post.
It then removes the top level categories from consideration.
So if you have an ashtray post which is categorised "cigar" and "ashtray" and you add a View as described above, this code will remove the parent "cigar" category from the matches, so it will find other posts with the ashtray category, but not lighter posts which also have the cigar category.