tribe_get_events start and end date problem

Home Forums Calendar Products Events Calendar PRO tribe_get_events start and end date problem

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #96485
    Cyndi Masters
    Participant

    <p>I saw a thread similar to this that had been closed, but nothing in the thread seemed directly relevant. I am running a custom query in the header.php file of our theme to pull the current days’ “open” vs. “closed” hours, so it can echo those values in a little wooden sign we have in the left sidebar. This works fine on all pages EXCEPT for the page we are actually using to show the calendar (/events). For whatever reason – and I’ve analyzed the query results with no end of var_dumps and such – the same exact query that works on every other page when the header loads returns multiple events instead of just the one in question for that date. I have spent hours trying to figure this out and am tearing out my hair. Here is the basic query. Start and end date are calculated and passed in as $current_date and $end_date.</p>

    $sf_events = tribe_get_events(
                array(
                    'start_date' => $current_date,
                    'end_date' => $end_date,
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'tribe_events_cat',
                            'field' => 'slug',
                            'terms' => 'splashin-safari-hours'
                        )
                    )
                )
        );
    

    <p>To make sure something odd wasn’t happening with my $current_date and $end_date variables themselves, I dumped the values from several points in the template to make sure they hadn’t changed. They don’t – they remain as expected, both on the pages where it works right and on the page where it works wrong. It simply ignores the date criteria on the /events page ONLY. I have tried querying directly with WP_Query, but couldn’t get that to filter correctly for the dates. I even tried calling TribeEventsQuery::getEvents() as a static function instead of using tribe_get_events to see if your wrapper function was doing anything weird. No dice. Again, the query works correctly on all other pages. Any ideas? I’m imagining it must have something to do with the fact that the /events page is generated by one of your templates, but I can’t seem to figure out what the difference is.</p>

    #97218
    Barry
    Member

    Hi @dbswebsite,

    We can’t help too much with custom development tasks like this one, but here are a few things you could investigate:

    • Could you move the code out of the template and into your functions.php file (or a plugin) and run it on the init action? You could go on to pull the result back into your template at the appropriate point and may find the results are more consistent
    • If you want to keep the current order of operations it may be that the dates you are providing are being overridden because of the nature of the event view being requested (if the query’s eventDisplay property is upcoming as it would be in list view, for example, the end date will be set to an empty value) – so explicitly setting an appropriate value for eventDisplay (like custom, but you may need to experiment a little) could be an alternative approach

    Do either of those help/give you a few more avenues to explore?

    #97631
    Cyndi Masters
    Participant

    Adding ‘eventDisplay’ => ‘custom’ seemed to fix the problem. It might be a good idea to mention in your documentation that ‘eventDisplay’ can tend to default to ‘upcoming’ and – more crucially – that this causes it to ignore even an explicitly passed end date argument. Would have saved me hours of misery. Thanks.

    #134816
    Barry
    Member

    We’re doing a little housekeeping and I’m going to go ahead and close this thread as it’s fairly old at this point!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘tribe_get_events start and end date problem’ is closed to new replies.