Posted: August 2, 2023 at 9:24 am
Is there a way to filter the tickets shown when using the ticket list shortcode? I’m looking for a simple way to show some tickets on one page, and some on another. All are for the same event and date/time. All I would really need is a filter or shortcode argument that could exclude certain tickets in a given context. |
|
There’s a filter run on the tickets displayed on the ticket selector which sound like what you need. Take a look at Is that what you need? |
|
I think this is definitely the right track. Forgive me if I’m wrong, but it looks like all of the props of the tickets are protected (if I’m reading this right when var_dumping $tickets). What would be the best way to access the ID of each ticket assigned for the event? Here’s basically what I am trying to achieve, if that paints a clearer picture.
I found the filter you suggested, but I’m having trouble understanding what the safest way is to modify it in this instance because of the amount of data in the $tickets object. |
|
Clarification, when I say ‘modify’ I mean via my own custom function added to functions.php, not modifying the source code itself. |
|
Yep, a lot of properties (and methods) are, we have getters and setters for most.. which leads onto…
I’m not a far on var_dump, personally, I use Kint and there’s a plugin for it: https://wordpress.org/plugins/kint-debugger/ BUT, they haven’t updated it to be PHP 8 compatible, so someone forked it and did just that: https://github.com/DuckDivers/kint-debugger Install that as a plugin and using That will give you a MUCH better output and if you view the methods available on the object you’ll soon find everything you are looking for 🙂
Hmmm so you’ll already have the exact ticket ID’s for each page you want to display these? Where will you have those? I’m wondering if it’s going to be quicker/more efficient to just repull the tickets using the ID’s or filter the array. |
|
Thanks for the tip on Kint, I’m eager to try it. Unfortunately, it’s not working, or I’m doing something wrong. Here’s my code so far, just for testing the output.
But when I run that (with either version of Kint active), I get the following: Also when I var_dump($ticket->ID) in a foreach loop i get NULL. To your point at the end of your last response, what I meant was I am going to know the tickets I want excluded ahead of time, so if I can just filter the array, that would work for what I need to do. The only reason I am doing this programmatically is because on one page I want to show tickets 1, 2, and 3, and on another page I’ll want to show tickets 4, 5, and 6, but I still need everything under one event and datetime. So for the first page I was thinking I would just exclude 4, 5, and 6, and vice versa for the second page, but I am open on what the best way to do that actually is. |
|
No, your not doing anything wrong, that’s from a change we made that’s been fixed in the next version, it only comes up when using Kint (or trying to access the property). The fix is to go to: Find Change it to Now kint should work. I usually don’t advise modifying core, but as that’s a change we’ve already included in our next version of EE it wont matter here.
Its a method so:
Should output the value.
yeah, use the method you currently are, if it doesn’t work out for what you need we’ll look at switching it out. |
|
Okay, I’ve got most of the logic working now, I’m still struggling with actually filtering out the unwanted ticket. I thought unset would work, but apparently it has no effect. Here’s my code so far: All of the test |
|
So unset() destroys the variable you pass to it. Your passing So you need to do something like:
Your foreach now has the key from each element in the array and each element is passed as Then swap your Thats removing the elements from the array that your filtering and then returning. |
|
Perfect! This is exactly what I needed. Thank you for your help. In case anyone else runs into a similar issue, here’s what I ended up doing. If I could ask a followup question, is there any documentation of the methods/filters available for stuff like this? I’m pretty good at following along or modifying examples, but a lot of this is way over my head. |
|
So, I’d love to say yes, but, we have literally thousands of hooks within EE. Filter hooks are all prefixed with Action hooks are all prefixed Searching the codebase will return roughly 3000 hooks, not including the dynamic versions where a hook name is generated on the fly as steps progress or the WP core hooks that also apply, so there are a LOT of hooks to document. Adding documentation for all of those is going to take a long time and unfortunately for the number of users it would actually benefit we can’t put it as a high priority as much as we would love to. Developers (who the hooks are intended for) will know how to search/use them or will at least find the hook and post up requesting additional details if they can’t figure something out specific to our code base, I/we will help with those if we but also can’t write out custom functions for people without purchasing a support token (we simply don’t have the capacity to take on custom snippets). In short, as much as we’d love to walk through the documentation for all of Event Espresso we have to prioritise where we spend the time doing so. Documentation/examples for customizations is not something we support, although we do add the details we can when possible 🙂 |
|
The support post ‘Ticket List Filtering’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.