Sauter la navigation

[Résolu] Filtering a view from a field

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

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)

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

Dernière mise à jour par ericK-4 Il y a 5 années et 1 mois.

Assisté par: Minesh.

Auteur
Publications
#1536949

Hello,
I still in the dev of my advocate site. The search function works great but my client want one more thing. After a search and after to look at the profile of an advocate, he wants to see one more time the advocates working in the same town.

So I make a view to display the result of the profile and in this view an another view with filtering by town by nothing shows up.

For info, the adress is repeater group and coordonnées is the parent of this repeater group
Here is the url
lien caché

Thanks for your help !

#1537221

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that on the following singe page under the section "Some advocate in the same town", you wan to list the other posts that belong to the same town - Versailles?
=> lien caché

If this is correct, I need to first review your existing view, can you please share the screenshot of the edit view page that is displayed on the following page:
=> lien caché

You can also share the screenshot of the custom field group that holds the repeating field group.

#1537245
screenshot-erik.jpg

Hi Minesh
Do you mean that on the following singe page under the section "Some advocate in the same town", you wan to list the other posts that belong to the same town - Versailles?
YES !
You find screenshot setting.

Thanks
Eric

#1537279

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Ok - It's not clear with your screenshot the Repeating Field Group is attached to what post type?

However - what if you just duplicate the view you created and then with that duplicated view, just change the Query Filter and set the option "Shortcode Attribute" and add the shortcode attribute name for example city:

[wpv-view name="your-view-slug" city="[types field='ville'][/types]"]

Where;
- replace your-view-slug with your view slug

More info:
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

#1537447
capture-erik02.jpg

Hi Minesh
Ok I put your shortcode but that returns ALL the towns
what I mean it is in the single page if the advocate works in “Versailles” show me all the advocates working in “Versailles” only
Hoping that is clear with my poor english
Thanks for your support

#1538251

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

It looks like there is something missing - I do not know why you are adding the post-relationship filter and add the shortcode attribute to city.

You need to add the custom filed filter in addition to post-relationship filter. If you do not know how to do it, please share access details and I will be happy to assist.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1538565

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Thank you for sharing the access details.

I checked and the thing is that you added the view as given under - outside the view loop.

<h1>Some advocate in the same town  </h1>
[wpv-view name="avocat-same-ville" currentcity="[types field='ville'][/types]"]

The thing is that outside the view's loop [types field='ville'][/types] shortcode will not return anything as the field ville belongs to the repeating field group which may have multiple entries.

So, we need to filter the view with the field "barreau" - for example;

<h1>Some advocate in the same town  </h1>
[wpv-view name="avocat-same-ville" currentcity="[types field='barreau'][/types]"]

Please check how the view's query filter is setup:
=> lien caché

Filtre de champ personnalisé Supprimer  Modifier
Sélectionner les éléments avec le champ :
Ville est un chaîne comme VIEW_PARAM(currentcity) 

And to ignore the same post and make sure it should not display again as you are already on that post, we need to use the conditional statement to check the current page ID and parent post ID.

<wpv-loop>
  [wpv-conditional if="( '[wpv-post-id item='@coordonnees.parent']' ne '[wpv-post-id item='$current_page']' )"]
		[wpv-post-body view_template="loop-item-in-avocat-same-ville"]
  [/wpv-conditional]
	</wpv-loop>

Please check: lien caché

#1538625

Hi Minesh
Thanks for your explanation. It becomes more comprehensible for me how toolset works but the road is long 😉

But can you explain me why for example at
lien caché
Her info is repeating twice at the top

and another case for example for this (town : roubaix):
lien caché
It return the town "lille" as result

Again thanks a lot for your help !
Eric

#1538635

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

The entry is repeating on the following page: lien caché

because, if you check in the backend, there are two repeating field entries:
=> lien caché

With the following URL: lien caché
- if you check the page in admin section, the field "Barreau" holds the value - Lille
lien caché

And as I informed you in my previous reply, we are filtering the results using [types field='barreau'][/types].

As you can see - you want to display the related parent information, and the parent will be the same for all repeating field group entries, what we can do is, we can limit the result to 1 as all repeating field group item will have the same parent where you are displaying results:
lien caché

if you accept this way, we can move the following view withing the view's loop for the following view:
=> lien caché
For example:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
<div class="ville-container">
<ul class="wpv-loop js-wpv-loop ville-bloc">
		<wpv-loop>
			<li>[wpv-post-body view_template="element-de-boucle-dans-liste-des-villes-et-tromni"]</li>
                       	</ul>
</div>

 
<h1>Some advocate in the same town </h1>
[wpv-view name="avocat-same-ville" currentcity="[types field='ville'][/types]"]

		</wpv-loop>

	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]Aucune coordonées disponibles[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

As you can see we move the view within the view's loop and there we will have access to the ville field value.

You can try the above approach and I think that is suitable for you. You just need to copy/paste the above code within the following view's loop editor.
=> => lien caché

#1538647

Hi Minesh,
Thanks it works ! Last question if I want to put a message if there's no town availalble, can I make a conditionnal statement on the view itself ?

Les nouveaux fils créés par Minesh et associés à celui-ci sont repris ci-dessous :

https://toolset.com/fr/forums/topic/split-filtering-a-view-from-a-field-conditionally-display-the-view-based-on-town/

#1538655

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Great and glad to help.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery. You should resolve this ticket.

I've split the ticket with your new question, I'll follow up with the following ticket.
https://toolset.com/forums/topic/split-filtering-a-view-from-a-field-conditionally-display-the-view-based-on-town/

#1538831

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

You can also mark resolve this ticket 🙂

#1538849

My issue is resolved now. Thank you!