Home › Forums › Calendar Products › Events Calendar PRO › Display tribe_get_events into the list view
- This topic has 7 replies, 2 voices, and was last updated 10 years, 11 months ago by
Barry.
-
AuthorPosts
-
April 28, 2015 at 11:09 am #959064
Pablo
ParticipantDear supporters,
I want to filter the events displayed on my list view based on the value of a ACF field. I have added a new route: /events/target/{target_name} (being target name the value of the ACF).
The plugin I used for adding a new route, allows me to callback a template.
I have built my filtered events alright with this simple query:
function filter_events_by_target_age($target_age)
{
// Retrieve the next 5 upcoming events
$events = tribe_get_events( array(
'meta_key' => 'target_public',
'meta_value' => $target_age
) );
}
But now I would like to display these events with the list view template. How could I do that? Should I set a global variable before calling the template?
Regards,
April 29, 2015 at 4:50 am #959185Barry
MemberHi Pablo,
The best approach would be to use a hook like tribe_events_parse_query or tribe_pre_get_posts and modify the existing query appropriately.
Both these hooks are essentially specialized forms of WordPress’s own parse_query and pre_get_posts hooks – which you are also welcome to use.
This is definitely a more advanced customization to make and so if you’re unsure about the best way to use those hooks I’d recommend checking out the relevant WordPress Codex entries before going any further 🙂
April 30, 2015 at 2:15 am #959476Pablo
ParticipantThanks Barry,
I finally created a new filter on the filter bar based on my new custom field (ACF).
The problem now is that the filter url does not take effect if I don’t make visible the new filter on the filter bar. Is that the expected behaviour?
In other words, I can not use the filtering url unless the filter itself is visible in the filter bar?
Thanks,
April 30, 2015 at 7:20 am #959609Barry
MemberHi Pablo,
I don’t feel I fully understand what you’re describing here – and please also bear in mind that our level of support for customizations like this one is pretty limited.
In other words, I can not use the filtering url unless the filter itself is visible in the filter bar?
So I don’t know exactly what you’ve put in place at code level but I wouldn’t have thought there would be any difficulty in using the hooks I listed earlier to filter the result regardless of what might be visible in Filter Bar.
Perhaps you just need an alternative approach for triggering them?
May 1, 2015 at 3:44 am #959811Pablo
ParticipantDear Barry,
I just solved it by creating a new filter field on the filter bar. That gives me a genuine url (the one you get when you filter for the new field) and then I can use that url as a link in the events that match that field.
For example like this:
http://trdevents.pablomargareto.com/?action=tribe_list&tribe_paged=1&tribe_event_display=list&tribe_target_filter%5B%5D=youngsEverything works as expected, except if I disable the new field (from the settings panel). Then, when I go to the previous link the results are not filtered at all.
Is this the expected behaviour?
May 1, 2015 at 6:49 am #959828Barry
MemberYes – that’s expected: unless you explicitly work around it, a filter extending the Tribe__Events__Filterbar__Filter base class will not modify the query if it is not currently active.
May 1, 2015 at 8:01 am #959848Pablo
ParticipantGreat!
Thanks for your help!
May 4, 2015 at 4:46 am #960160Barry
MemberOur pleasure 🙂
Since we’re in custom development territory here I’ll go ahead and close out this topic, but of course if we can help with anything else please don’t hesitate to create new topics as needed and one of the team will be only too happy to help.
Thanks again!
-
AuthorPosts
- The topic ‘Display tribe_get_events into the list view’ is closed to new replies.
