Skip Navigation

[Gelöst] Display view with filter on 2 parent posts

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.

This topic contains 2 Antworten, has 2 Stimmen.

Last updated by romanB-3 vor 4 Jahre, 4 Monate.

Assigned support staff: Luo Yang.


I have a view showing all child posts with 2 filters, one for each parent post.
Here is the code I set up :

	[wpv-control-post-relationship ancestors="produit" url_param="wpv-produit-filter"]
		<div class="form-group">
		  <label>[wpml-string context="wpv-views"]Produits[/wpml-string]</label>
          [wpv-control-post-ancestor type="multi-select" ancestor_type="produit"]

	[wpv-control-post-relationship ancestors="fournisseur" url_param="wpv-fournisseur-filter"]
		<div class="form-group">
		  <label>[wpml-string context="wpv-views"]Fournisseurs[/wpml-string]</label>
          [wpv-control-post-ancestor type="multi-select" ancestor_type="fournisseur"]

But in the filter section, I can't find how to add the second post relationship filter...
Thank you.


Luo Yang

Languages: Englisch (English ) Vereinfachtes Chinesisch (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Dear roman,

This is expected result, you an setup only one post type relationship filter in a single view, and here is a workaround with some custom codes using Views filter hook wpv_filter_query, for example:
1) edit your view, add a " Post relationship filter":
Select posts that are children of the Post with ID set by the URL parameter wpv-produit-filter.
eg. hidden link

2) Use filter hook wpv_filter_query to apply another filter, add below codes into your theme/functions.php:

add_filter( 'wpv_filter_query', 'filter_by_parent_fournisseur_func', 999, 3 );
function filter_by_parent_fournisseur_func( $query_args, $view_settings, $view_id ) {
    if ( $view_id == 99 && isset($_GET['wpv-fournisseur-filter'])) {
		$query_args['meta_query'][] = array(
				'key'     => '_wpcf_belongs_fournisseur_id',
				'value'   => $_GET['wpv-fournisseur-filter'],
    return $query_args;

add_filter('wpv_filter_register_url_parameters_for_posts', 'add_extra_url_param_func', 10, 2);
function add_extra_url_param_func($attributes, $view_settings){
	if($view_settings['view_id'] == 99){
		$attributes[] = array(
			'query_type'=> 'posts',
			'filter_type'=> 'post_relationship',
			'value'=> 'custom_field_value',
			'attribute'=> 'wpv-fournisseur-filter',
			'expected'=> 'number',
	return $attributes;

Please replace 99 with your view's ID


That is just GREAT.
Thank you very much !