Home › Forums › Calendar Products › Events Calendar PRO › Query parameter for category
- This topic has 8 replies, 3 voices, and was last updated 10 years, 9 months ago by
Support Droid.
-
AuthorPosts
-
March 14, 2015 at 4:54 am #948309
Vincent
ParticipantHi,
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.
March 14, 2015 at 11:10 am #948342George
ParticipantHey 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,
GeorgeMarch 15, 2015 at 9:52 am #948425Vincent
ParticipantHi,
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=yogaAnd I would like to add the parameter for the event’s category.
Thank you!
March 15, 2015 at 11:09 am #948439George
ParticipantHey 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=5That’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,
GeorgeMarch 15, 2015 at 2:41 pm #948456Vincent
ParticipantHi,
Thank you very much! But could you tell me where I could find those tag IDs?
Vincent
March 16, 2015 at 1:50 pm #948675George
ParticipantHi 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!
GeorgeMarch 17, 2015 at 5:32 am #948820Vincent
ParticipantHi,
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
March 18, 2015 at 8:04 am #949127George
ParticipantHey 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
July 7, 2015 at 6:31 am #983878Support Droid
KeymasterThis 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. -
AuthorPosts
- The topic ‘Query parameter for category’ is closed to new replies.
