Filter by Custom Taxonomy + Events Categories

Home Forums Calendar Products Filter Bar Filter by Custom Taxonomy + Events Categories

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #827309
    Nancy Barraza
    Participant

    Hi!, I’ve been trying to find an answer about how to do this, i need be able to use the filter bar, to filter by events categories and a custom taxonomy named “event type” where we can find types as “twitter-chat”, “google hangouts” etc.

    I followed up this recommendation https://theeventscalendar.com/support/forums/topic/filter-for-additional-field/

    Everything looks fine, but when i started to testing, i can’t get the filter for both things.

    It filter by Event Category OR Custom Taxonomy (“Event Type”), instead both.
    I mean, if i have an event with category a, but event type twitter-chat, and another with category b, but event type: google hangout.

    It returns the result only for the event type, and not filtering by the category.

    Here the custom snippet that i created:

    In filterbar/lib/filters/TribeEventsFilter_Category.php file:

    protected function setup_query_args() {
    $this->queryArgs[‘tax_query’] = array( ‘relation’ => ‘AND’, array(
    ‘taxonomy’ => TribeEvents::TAXONOMY,
    ‘field’ => ‘id’,
    ‘terms’ => $this->currentValue,
    ‘include_children’ => false,
    ) );

    }

    and In filterbar/lib/filters/TribeEventsFilter_EventType.php file:

    protected function setup_query_args() {
    $this->queryArgs[‘tax_query’] = array( ‘relation’ => ‘AND’, array(
    ‘taxonomy’ => ‘event_type’,
    ‘field’ => ‘id’,
    ‘terms’ => $this->currentValue,
    ‘include_children’ => false,
    ) );
    }

    As i understand, this, get the args for tax queries in an array where the relation is ‘AND’ with the other taxonomy.

    Then, the query should filter where Category = B AND Event Type = ‘twitter-chat’
    And returns only the events that matches with that criteria, but… it is doing the query like:

    ‘Event type’ = twitter-chat, without consider the category selected.

    I understand, this can’t be a common support request, but, i have a deadline for this week to get this filter working, and i can’t wait for a new release, hope you can help me 🙁

    Thankyou

    #829575
    Barry
    Member

    Hi – that’s a great question – though it is (as you noted) a customization request and a fairly advanced one at that, so we can’t go into too much depth on this one I’m afraid.

    That said, I can certainly offer a few pointers and indeed I think on this occasion there is something for us to improve on (in our codebase), too.

    • It sounds like you are modifying core plugin code – that’s to be avoided!
    • Similarly, you are adding your new filter code to the core plugin directory – again, try to avoid that!
    • I’d guess the basic problem here is that your custom taxonomy filter’s tax query is overwriting the plugin’s own category tax query (or vice versa, which way round will depend on the order they are registered)
    • The reason such a collision doesn’t occur with the built-in category and tag filters is that the tag filter is making use of the tag__in query argument

    All in all then:

    • You need to merge existing tax query arguments into your custom filter’s tax query
    • Naturally you don’t want our category filter to wipe these out: so you’d probably need to wrangle things so your code runs after ours
    • I’ll make a note for us to check into this and see if we can avoid such collisions going forward

    I hope that helps!

    #835409
    Nancy Barraza
    Participant

    Indeed i’m overriding the core, but i’m going to create a custom extension after make it work, i was thinking change the logic a bit on it, and instead to use a custom taxonomy, use a natural category to get the categories, and the event tribe categories to get the event types.

    Do you think the filter cat__in should work similar to tag__in?

    Please adivce

    #846121
    xrossglobalgroup
    Participant

    I’m not very technical myself, so I’m not sure that I understand the above correctly. On my overall events calendar page (with all events) I need visitors to be able to select and de-select event categories (e.g. arts & culture, food & drinks, day trips, etc). I namely organise way too many events and so I want to help my members to view only those they are interested in. Somewhere in the right column or above the main column there should be selection boxes. Is this already possible in TECpro? Or is this indeed a difficult custom job?

    #846597
    Barry
    Member

    Do you think the filter cat__in should work similar to tag__in?

    The category__in argument works in a similar fashion to tag__in, yes, and I believe both are ultimately transformed into taxonomy queries behind the scenes. There is a great resource on the WordPress Codex that goes into this in some more detail which could be worth reviewing:

    codex.wordpress.org/Class_Reference/WP_Query

    On my overall events calendar page (with all events) I need visitors to be able to select and de-select event categories (e.g. arts & culture, food & drinks, day trips, etc). I namely organise way too many events and so I want to help my members to view only those they are interested in. Somewhere in the right column or above the main column there should be selection boxes. Is this already possible in TECpro?

    Hi xrossglobalgroup!

    So this topic is concerned with customizing the Filter Bar plugin – if you’re only using Events Calendar PRO it isn’t going to be relevant, though Filter Bar is probably one way of achieving what you are looking to do here (check out our demo site to see it in action!).

    If you’ve got any more questions we’d be more than happy to help – but please do create a new thread of your own (just to avoid confusion and help us ensure fair and speedy service for everyone).

    Nancy Barraza: I don’t think there’s too much more I can do to help with this issue as it’s ultimately a custom development question – and so I will go ahead and close this thread. Of course, as with xrossglobalgroup, please don’t hesitate to create new threads if you have any further questions on different issues.

    Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Filter by Custom Taxonomy + Events Categories’ is closed to new replies.