Skip Navigation

[Résolu] Display view with filter on 2 parent posts

This support ticket is created Il y a 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 2 réponses, has 2 voix.

Last updated by romanB-3 Il y a 6 années et 9 mois.

Assisted by: 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.


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 !

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