Display tribe_get_events into the list view

Home Forums Calendar Products Events Calendar PRO Display tribe_get_events into the list view

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #959064
    Pablo
    Participant

    Dear 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,

    #959185
    Barry
    Member

    Hi 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 🙂

    #959476
    Pablo
    Participant

    Thanks 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,

    #959609
    Barry
    Member

    Hi 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?

    #959811
    Pablo
    Participant

    Dear 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=youngs

    Everything 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?

    #959828
    Barry
    Member

    Yes – 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.

    #959848
    Pablo
    Participant

    Great!

    Thanks for your help!

    #960160
    Barry
    Member

    Our 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!

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Display tribe_get_events into the list view’ is closed to new replies.