Adding Custom Filter to Filter Bar

Home Forums Calendar Products Filter Bar Adding Custom Filter to Filter Bar

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #605314
    workforcesoftware
    Participant

    I have used this code below to add a filter to my Filter Bar:
    https://theeventscalendar.com/support/forums/topic/adding-custom-filter-to-filter-bar/
    How do I get the Location choice show up on the /events page?

    #656581
    Brook
    Participant

    Howdy workforcesoftware,

    Sorry it took me a bit to respond. I was discussing this topic with the team and then I forgot to get back to you.

    We decided we really want to come up with a tutorial for accomplishing this that shows the best and easiest way now that the API has matured. But, in fairness that could take a while. We have a number of tutorials we are working up right now.

    The code that Barry shared adds a filter to the “Available Filters” in WP Admin > Events > Settings > Filterbar. However,now you have to add lots of logic to get that filter to do more than just show up. There is an easier way. The TribeEventsFilter class’s __construct() function will take care of that for you. Simply extend it, then pass it the name of your filter and the unique slug ($_GET key) you want it to use. Here is an example. Notice the last line.

    Hopefully this makes a lot more sense with the example. That filter is tested and working. I included a few comments in there to help explain it some. Let me know if i can be of further help. We do want to make this much easier in the future by having a full tutorial. Cheers!

    – Brook

    #659694
    workforcesoftware
    Participant

    Hi Brook,
    Just to clarify, I should add this entire code to my functions.php file and change the “filter” to my custom filter name of Location, which is a select field? Thanks for the help.

    #663878
    Brook
    Participant

    Not quite. This was an example of how to create a taxonomy filter. The main goal was to demonstrate how easy it is to add a filter. Basically you just create a class which extends TribeEventsFilter, then instantiate it. The one line instantiates at the bottom instantiates and assigns it a name and slug.

    If you want to create a filter based on additional fields you will need to modify or otherwise mimic that example snippet. The function setup_query_args() is where you will your put your extra query params for when the filter is actively filtering events. The function get_values() returns the array of values that the user can select for this filter. Finally, the function get_type_field() allows you to craft the HTML elements output by the filter front end. Each element will be populated with the values from get_values(). Combined these functions amount to a custom filter. Of course, it will be up to you to fill each of those functions with your desired logic.

    I am very keen on making a full tutorial about this in the future, to make it easier for those who are not versed in PHP. Furthermore we also want to add Additional Fields to the filterbar, as noted on that feature request. Please vote that up if you would like to see it happen. In the mean time though, it will require coding as outlined in the above paragraph.

    Does that make sense? Let me know!

    – Brook

    #809172
    Brook
    Participant

    Since this topic has gone for a spell without a response I am going to archive it. If you do need anything else please feel free to open a new topic. Cheers!

    – Brook

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Adding Custom Filter to Filter Bar’ is closed to new replies.