How to list all events for current category
-
This may be more of a PHP question than something about this plugin specifically.
I’m beating my head against the wall after a couple days. I must be doing something stupid, but I surrender. I had this working, and after building out more of the site came back to this page and found it broken. Everything I tried to fix it has failed.
In the event page I want to list all other events for the current event’s category. The basic idea is to call eo_get_events() and pass ‘event-category’=> as the slug for the current post’s category. Note that I do assume there’s only one category. That’s all I care about.
So I do this:
$terms = get_the_terms( $post->ID, 'event-category' );
Then this (which had worked):
$upcoming = eo_get_events(array( 'event-category'=>$terms[0]->slug
For some reason, this broke and I’ve been banging my head to get it working again.
All attempts at PHP have failed me, but I readily admit PHP is a new language for me (yet I have programmed in many others).
If I use this, it does pull out the slug I’m looking for:
foreach ( $terms as $term ) $currentCategory = $term->slug;
So why does the “foreach” loop work, but EVERYTHING else I’ve tried to access the current slug has failed.
How can I get to the first occurrence, without looping through the array with foreach?
- The topic ‘How to list all events for current category’ is closed to new replies.