Skip Navigation

[Resolved] Display related posts based its terms

This support ticket is created 3 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Paulo Ramalho 3 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#2300153

Hi.
It is the first time I use Toolset Relationships, and it is very interesting.
I have the following code in my single-(cpt-slug).php and it works correctly.

<?php $child_posts = toolset_get_related_posts( get_the_ID(),
'podcast-capitulo', array( //Relationship slugs
'query_by_role' => 'parent',
'return' => 'post_object' ) );
foreach ($child_posts as $child_post)
{ ?>

Now I need to display this relationship (podcast-capitulo) only from a term called "casos-reales" under the taxonomy "genero".
Thanks in advance, any help will be fully apreciated.

#2300957

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The function toolset_get_related_posts() do not support the tax_query argument.

But I've workaround to offer you, instead of using toolset_get_related_posts() function, you can use the WP_Query:
For example:

global $post;
 $query = new WP_Query( 
    array(
        'post_type' => 'podcast',
        'posts_per_page' => -1,
        'toolset_relationships' => array(
            array(
                'role' => 'child',
                'related_to' => $post->ID,
                'relationship' => 'podcast-capitulo''
            )
        ),
      'tax_query' => array(
                        array(
                        'taxonomy' => 'genero',
                        'field' => 'slug',
                        'terms' => array('casos-reales'),
                         )
                      )
    )
);
 $child_posts = $query->posts;

foreach ($child_posts as $child_post)
{ ?>

Where:
- I already applied post type, taxonomy and term slugs, you can change it if required.

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

#2302275

Yes, it works and it's a good idea, thank you very much.
I've been looking in the Toolset documentation and haven't found those arguments on toolset_get_related_posts().
My problem is solved.
Thanks again.
Paulo

#2302277

My issue is resolved now. Thank you!