Home › Forums › Calendar Products › Events Calendar PRO › get_tribe_events() – start_date and end_date not working
- This topic has 21 replies, 4 voices, and was last updated 13 years, 5 months ago by
Barry.
-
AuthorPosts
-
October 22, 2012 at 8:07 am #26949
Nick
ParticipantHello,
I’ve setting up a custom advanced search and tried to replicate the start_date and end_date query from the https://theeventscalendar.com/support/documentation/the-events-calendar-template-tags-general-functions/#functiontribe_get_events page.My queries ignore the start_date and end_date parameters. All other parameters work (cat, venue, search string, etc). I’ve tried the exact code from the example, as well a re-writing it. Note, this is in the search template page – but I’ve tried it on a standard page template with no dice.
Here is a screenshot of results and the print_r of the $args I passed to get_tribe_events(). https://dl.dropbox.com/u/4014819/Screen%20Shot%202012-10-22%20at%2010.04.25%20AM.png
As you can see the event listed is before the start and end date I provided to the query – yet it still appears.
Thanks for your assistance.
October 22, 2012 at 1:21 pm #26980Barry
MemberHi Nick, can you try expressing the dates in the following format?
Y-m-d H:i:s
October 22, 2012 at 2:04 pm #26984Nick
ParticipantHi Barry,
Appreciate your assistance. Changed and same result: https://dl.dropbox.com/u/4014819/Screen%20Shot%202012-10-22%20at%204.01.52%20PM.png.I’ve pastebin’d my code here: http://pastebin.com/LQp7GhHV
I’m building the query array from url parameters passed from a form. I’ve tried several date formats, but assume it should be using the Y-m-d like in your code samples. I even tried to re-write this is a wp_query using meta_query – but that also works except for the date range filtering.Thanks again for your help,
NickOctober 22, 2012 at 2:51 pm #26988Barry
MemberHey Nick, I’m unsure why you are having problems. This snippet works as I would expect it to: http://pastebin.com/adcVxb0R (returning up to 8 events in October where the category is as specified).
Perhaps the context of your code or something else is impacting?
October 24, 2012 at 9:22 am #27131Nick
ParticipantHey Barry,
I tried this manual query as well: http://pastebin.com/xFLqjM3g
In this case I have a event at 10/25/12 7:00 pm, and I set the date range to 2012-11-01 to 2012-11-31, and the event still appears when it has expired. It seems to simply ignore the start_date and end_date parameters.Then I tried setting “upcoming” to “all” and suddenly everything started working. I can emulate “upcoming” by simply limiting the date to today forward in my form. Seems like the “eventDisplay” parameter was the issue.
Thanks,
NickOctober 24, 2012 at 9:47 am #27132Nick
ParticipantHm, now it only works if I ask for a venue, search string, or event_cat in addition to the start_date/end_date – not with just the start_date/end_date.
October 24, 2012 at 9:54 am #27134Nick
ParticipantOk, think I got it. We had a few events that had messed up end date entries.
So, in the end, the fix was the ‘eventDisplay’ => ‘all’
Thanks for your help.
October 24, 2012 at 9:57 am #27136Barry
MemberGlad to hear you’re all sorted 🙂
October 24, 2012 at 10:16 am #27137Nick
ParticipantI’ve noticed you guys use get_posts to run your queries. Wouldn’t it be better to use wp_query as it’s more efficient and also provides important info like max_pages for pagination. Don’t suppose you guys have it documented anywhere on how to write the proper meta_query for your dates?
Thanks,
NickOctober 24, 2012 at 12:20 pm #27143Barry
MemberHey Nick,
I’m afraid I can’t really comment on why get_posts() might have been preferred to directly instantiating and working with a WP_Query object in the code you looked at, though personally speaking I wouldn’t really see it as a massive inefficiency: it’s a small and compact function after all and takes care of setting a few default parameters, so one might even say it adds to the readability of the code.
In fact, it’s also totally possible to inspect the value of the max_num_pages property – get_posts() itself uses WP_Query so you could grab a reference to that object and look at its properties after the query has run if needed – thankfully WordPress is pretty flexible that way 🙂
Regarding meta queries – if you are writing some custom code using WP_Query then you would follow the guidelines documented for this in the codex – there are certainly snippets lying around the forums and in our docs and tutorials though.
What is it that you want to do?
October 24, 2012 at 1:13 pm #27149Nick
ParticipantNow that I’ve solved the date range issue I noticed pagination doesn’t work properly. I’m tackling that issue now.
I’ve searched how to do pagination for get_posts() and as far as I now the only way is to do an offset hack. According to one of your own blog posts you guys came to the same conclusion – so you guys recommended wp_query.
https://theeventscalendar.com/queries-and-pagination/But if I use wp_query, I lose all that hard work you guys did building a post-meta date range query 🙂
So, that’s how I came to the conclusion of re-writing your date range query using wp_query’s meta_query parameter.
October 24, 2012 at 1:22 pm #27150Barry
MemberRight, well I think what Joey was saying was that for any custom queries that you may wish to build WP_Query could be a better choice than get_posts() (which may be used internally by The Events Calendar). Apologies if I misunderstood you there.
October 24, 2012 at 1:56 pm #27154Cheryl
ParticipantHello. I am also having a problem with this function. The end_date parameter works fine, but the start_date always starts from today instead of using my input date, which is in Y-m-d format. I’n not using the eventDisplay parameter.
October 24, 2012 at 2:43 pm #27156Cheryl
ParticipantMe again. Here’s the relevant code where $startdate and $enddate are in Y-m-d format:
$taxomonies = array(‘relation’ => ‘IN’);
if ( isset($events)) {
$array1 = array(
‘taxonomy’ => ‘tribe_events_cat’,
‘field’ => ‘id’,
‘terms’ => $events
);$taxonomies[] = $array1;
}$args = array(
array(
‘start_date’ => $startdate,
‘end_date’ => $enddate,
‘posts_per_page’ => -1,
),
‘tax_query’ => $taxonomies,
);global $posts;
$get_posts = tribe_get_events($args );October 24, 2012 at 3:23 pm #27157Barry
MemberSo here’s the thing: if you don’t specify a display type (via the eventDisplay argument) then it is treated as if you set displayType to upcoming.
Also, whether you deliberately set the display type to “upcoming” or allow it settle on this by default, the value of start_date is overriden and set to the current date.
Does that give a better understanding of what’s happening here?
-
AuthorPosts
- The topic ‘get_tribe_events() – start_date and end_date not working’ is closed to new replies.
