Skip Navigation

[Fermé] Filter posts with two parents

This support ticket is created Il y a 7 années et 9 mois. 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
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 2 réponses, has 3 voix.

Last updated by Beda Il y a 4 années et 1 mois.

Assigned support staff: Adriano.

Auteur
Publications
#286383

I am working on a site with a wines catalog. I have a CPT 'wines' , a CPT 'wine-producers' and a CPT 'wine-regions'. Each CPT wines can be a child of wine-producer AND wine-region.

Everything is working fine, but in the filter of the main catalog query I see that I can only filter against a single post-relationship.

How can I add filters for both parents?

Thanks

#286451

Hi Gian Luca,

You have to use a Views PHP filter for that, like this:

add_filter( 'wpv_filter_query', 'wpv_check_relationship', 10, 3 );
 
function wpv_check_relationship( $query, $setting, $views_ID ) {
if($views_ID == 123){
$query['meta_query'][] = array(
'key' => '_wpcf_belongs_wine-regions_id',
'value' => 'Here the ID of the parent',
'compare' => '='
);
}
return $query;
}

This code should be in functions.php and you have to replace "123" with the Views' ID, aldo "wine-regions" with the other parent slug you need to filter.

You can add a fix ID or use some WordPress function in order to get the current ID.

More information: https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards,

Adriano Ferreira

#1129604

Le sujet ‘[Fermé] Filter posts with two parents’ est fermé à de nouvelles réponses.