Skip Navigation

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

This support ticket is created Il y a 7 années et 2 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par romanB-3 Il y a 7 années et 2 mois.

Assisté par: Luo Yang.

Auteur
Publications
#552689

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

[wpv-filter-controls]
	[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"]
		</div>
	[/wpv-control-post-relationship]

	[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"]
		</div>
	[/wpv-control-post-relationship]
[/wpv-filter-controls]

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

#552853

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. lien caché

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

#552920

That is just GREAT.
Thank you very much !

Ce ticket est maintenant fermé. Si vous êtes un client de Toolset et que vous avez besoin d'aide, veuillez ouvrir un nouveau ticket d'assistance