Querying in custom Filter Bar filters

Home Forums Calendar Products Events Calendar PRO Querying in custom Filter Bar filters

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #970860
    Steve
    Participant

    I’m trying to set up some custom filters for Filter Bar. I need to do some things that don’t involve the simple system provided.

    I’ve set up a basic custom filter easy enough following the advice here: https://theeventscalendar.com/support/forums/topic/adding-custom-filter-to-filter-bar-2/ As long as you have a taxonomy or custom field you want to filter against, just populate the values for a drop-down, all works great.

    However, I’m trying to replace the ‘Cost’ filter with one that is simply a checkbox to filter and only show events that are free. I know this is possible with the ‘Cost’ filter, but we need the interface to be simpler, we don’t want comprehensive cost filtering, just “free?”, or show everything. And we need some other, more complex filters. I thought it would be good to start with the problems with this one, it may help on the way to the more complex ones.

    The code I’ve got so far is here: https://gist.github.com/gyrus/af981f6e3ab19a940b59

    Using Query Monitor the query being performed is this: http://pastebin.com/iETYQNep

    The join for the event cost meta field seems to give the alias mt1 to the meta table, but the OR condition seems to be using both this and the plain meta table name. Is this part of the issue? I wonder if this is something to do with the filter bar setup_query_args() setting args rather than concatenating them?

    Further, does this lead to issues with applying multiple custom filters at once?

    Anyway, it’d be good to get this simple one working first!

    #971081
    Josh
    Participant

    Hey Mike,

    Thanks for reaching out to us!

    I took a look at the code you provided and it appears to be correct. I tested it on my local install and the additional filter displays (https://cloudup.com/cAeZBojB_QN) and when I select the “Free” checkbox, it filters out the paid events that I do have on the calendar (https://cloudup.com/cgtWn4JHD53 excuse the misleading titles of some of the remaining events. These events no longer have costs attached to them).

    What issues are you experiencing when implementing this code?

    Thanks!

    #971229
    Steve
    Participant

    Apologies, yes, it seems to be working now I’ve stripped a lot of other custom stuff back.

    However, regarding custom filters in general, could you confirm something? If I have this in my custom filter class:

    protected function setup_query_args() {
    	$this->queryArgs = array(
    		'meta_query' => [query args]
    	);
    }

    Is that overriding all other meta queries being applied, or is it adding to the meta query? I’m assuming the latter, since otherwise multiple filters wouldn’t work together?

    #972187
    Josh
    Participant

    Hey Mike,

    Awesome! I’m glad this is working for you. As far as the code being referenced, that should add to the args for the query rather than fully replace. If you are noticing something different I’ll leave this thread open and you can come back with that here.

    Thanks!

    #984716
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Querying in custom Filter Bar filters’ is closed to new replies.