Query parameter for category

Home Forums Calendar Products Events Calendar PRO Query parameter for category

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #948309
    Vincent
    Participant

    Hi,

    I am developing my own search bar, and I would like know what is the name of the query parameter to search by category. I have tried tribe_eventcategory and put an array with the id of a category as a value but this does not work.
    I did not buy the Filter Bar plugin since I do not need it for now.

    Could you help me please ?

    Thank you.

    #948342
    George
    Participant

    Hey Vincent,

    You should be able to access the existence of and/or value of the events category in a query variable by using this bit of code:

    
    $query->query_vars[ TribeEvents::TAXONOMY ]
    

    Note that after the next public update, this will have to become this:

    
    $query->query_vars[ Tribe__Events__Events::TAXONOMY ]
    

    While we can’t help with your exact custom search functionality, one more thing I’d love to recommend here would be to read through the TribeEventsQuery class in the plugin files for the free version of The Events Calendar – after the next update, this class will be named Tribe__Events__Query, but regardless, it’s full of a lot of great code that you could reference for customizing the query object in your search functionality.

    Let us know if this helps!

    Cheers,
    George

    #948425
    Vincent
    Participant

    Hi,

    Thank you for your response.

    I’m actually developing it in JavaScript.
    The URL looks like this for now: http://xxx.com/events/?action=tribe_list&tribe_paged=1&tribe_event_display=list&tribe-bar-search=yoga

    And I would like to add the parameter for the event’s category.

    Thank you!

    #948439
    George
    Participant

    Hey Vincent,

    Thanks for clarifying your goals here. This is unfortunately not something fully built into the plugin, so you may need to make further tweaks to the code on your site to get things working exactly as you hope, which is a bit beyond the scope of our support here.

    However, the basic idea of what you’re trying to do would be to add two query params to your URLs. First would be “taxonomy”, i.e. &taxonomy=tribe_events_cat. Then, to filter by this taxonomy, you’d need to pass the ID of the specific Events Category you’re filtering by, e.g. &tag_ID=5.

    So something like this:

    
    {url}/?action=tribe_list&tribe_paged=1&tribe_event_display=list&tribe-bar-search=yoga&taxonomy=tribe_events_cat&tag_ID=5
    

    That’s your best place to start, but like I said, you’ll likely need to play around with this quite extensively and will need to build out a way for that tag ID parameter to be correctly generated for whatever category you’re filtering by.

    I hope this helps,
    George

    #948456
    Vincent
    Participant

    Hi,

    Thank you very much! But could you tell me where I could find those tag IDs?

    Vincent

    #948675
    George
    Participant

    Hi Vincent,

    There are several ways to do this – if you’re code-savvy, you can use things like _get_queried_object()->term_id_, but implementing all that into your customization is something you’ll have to take the reins on here.

    A simpler way, to be honest, is a little “Hacky”, but works fine! 🙂 Basically, just head to “Events Categories” in your admin, and hover over a specific category whose ID you want to find. Then, note what the _tag_ID_ URL parameter is set to in the URL string when you hover over it (or when you click to that category and see it in the URL bar, if your browser doesn’t show the URL on hover…).

    Here’s a screenshot illustrating this – in this example, my mouse is hovering over the “Barbecue” category → https://cloudup.com/c8wJvzJXs6Q

    Cheers!
    George

    #948820
    Vincent
    Participant

    Hi,

    I followed the instructions you wrote, but for some reasons it does not work… I tried with many tag IDs but it never changed the result of events I get.

    Do you have some idea why this parameter is not taken into account?

    Thank you,

    Vincent

    #949127
    George
    Participant

    Hey Vincent,

    That information should be correct information as far as passing the ID of an Event Category via URL, but to actually have filtering work based on that ID, as far as I can think you’d need to write extra code that looks for this ID and actively filters the results.

    This is not default feature and something usually only possible with an add-on like the Filterbar addon.

    For further information to help you take the reins on the custom coding, I’d recommend looking into and researching functions like pre_get_posts() that would let you customize queries before they run.

    — George

    #983878
    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 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Query parameter for category’ is closed to new replies.