Skip Navigation

[Résolu] Filtering view results using Modern Tribe's Event Calendar venue State

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

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Marqué : ,

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

Dernière mise à jour par joshM-4 Il y a 4 années et 9 mois.

Assisté par: Nigel.

Auteur
Publications
#1517197

Tell us what you are trying to do? Filter an events view by the State/Province where the event is taking place

Is there any documentation that you are following? No

Is there a similar example that we can see? Not that I can think of

What is the link to your site? lien caché

The State/Province information is pulled from the Venues post type that is connected to the Events. The data I'm trying to filter with is in the _VenueStateProvince field from the Venue, but it's just not working and I can't quite piece together in my head what needs to be done so that I can filter events (tour dates) by this _VenueStateProvince field.

I'll provide login information in a private note, but the view I'm messing with is found here: lien caché

Thanks for your help.

#1518051

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Josh

The _VenueStateProvince field belongs to the Venue post type?

In that case you can only filter Venue posts by that field, not Events. You can only filter something by its own properties, not by properties of something else.

This is in the context of WordPress queries (using the WP_Query class, which Views provides a visual GUI for).

You can construct custom database queries for this (or use multiple simpler queries) but that involves writing custom code, and you might be better off asking The Events Calendar how one would do it (using WP_Query): they may well have some helper API functions that would help.

It may by possible with nested Views where you initially query and filter the venues and then show the events linked to those venues, but that would very much depend on how the event and venue posts are connected. Do you have details or documentation of that?

#1519153

Hi Nigel,

That is in line with what I thought might be the case but I wasn't 100% sure. It does leave me with a final question/possibility—if I put the venues and events in a connected relationship via Toolset, do you think I would then be able to set up the filtering by State/Province?

If you can see a path to make that happen and have any advice I'll give it a go. Thanks for the help.

#1520279

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

if I put the venues and events in a connected relationship via Toolset, do you think I would then be able to set up the filtering by State/Province?

Unfortunately not, filtering by fields of related posts is a part of the post relationships project that never got completed (you can vote for it here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/).

When you say "filter events" I'm not sure whether you mean a static filter or whether you mean a front-end filter control as with a custom search.

Let's consider a static filter for now.

So, we have a View which shows events, and we only want to return events where the venue is in Maine, for example.

It helps if you are familiar with the WP_Query class used by WordPress to retrieve posts and the options available: https://developer.wordpress.org/reference/classes/wp_query/

The principle is that you need to run a pre-query of venues before running the main query of events that are connected to those venues.

You query venues that are in Maine (using the _VenueStateProvince field) to generate a list of possible venues.

You then query events that occur at these venues. I don't know anything about how that connection is stored by the plugin to help with that. Surely they have an API that can perform such queries? Their documentation or support should be able to help work that part out.

It may be if the queries are complex (because of how the data is stored) that you need to run both queries, the initial query for venues and the subsequent query for matching events, in code, but then if you are able to generate an array of event post IDs you can use the post__in argument (of WP_Query) where you essentially spoon-feed the View the IDs of the posts it should return and then you can still benefit from the output section of the View to generate the visual results even though the querying itself was done in code.

Sorry I can't be more specific without knowing the details of how the plugin stores its data and the API available.

From the Toolset side, you create a View for events.

You would then use the wpv_filter_query API hook (https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query) to add your custom code.

It would first query the venues according to the state.

It would then either perform another query for the matching events (or use one of the plugin's API functions) and update the View query args for the post__in parameter with an array of the event IDs, or if the data that connects the events to the venues is stored on the event posts in a simple way it may be possible to have the View perform the event query by updating its query arguments.

#1521125

Nigel, thank you very much for taking the time to answer in detail. I feel like I have a framework to approach this with now.