Home › Forums › Calendar Products › Events Calendar PRO › Problem with start_date in tribe_get_events in 2.0.4
- This topic has 16 replies, 5 voices, and was last updated 8 years, 9 months ago by Support Droid.
-
AuthorPosts
-
March 15, 2012 at 11:08 am #16808MikeParticipant
I’ve tried hacking it from a number of directions, but the start_date parameter in tribe_get_events() always returns the current date.
Here’s code I’ve been using:global $post;
$current_date = date(‘j M Y’,strtotime(‘1 day’));
$end_date = date(‘j M Y’, strtotime(‘7 days’));
$all_events = tribe_get_events(
array(
‘start_date’=>$current_date,
‘end_date’=>$end_date,
‘eventDisplay’=>’upcoming’,
‘posts_per_page’=>10,
‘tax_query’=> array(
array(
‘taxonomy’ => ‘tribe_events_cat’,
‘field’ => ‘slug’,
‘terms’ => ‘theater’
)
)
)
);March 15, 2012 at 3:37 pm #16823RobMemberHey Mike. Thanks for the heads up here; let me get Jonah to double check here, as this is a bit outside my area of expertise. Sit tight and he’ll respond when he hits the forums next!
March 16, 2012 at 9:21 am #16843JonahParticipantHi Mike, the above code works for me once I take out the tax_query – are you sure you have an event within that range in that category?
March 26, 2012 at 8:51 am #17149MikeParticipantJonah, I’m running in a sandbox now, so I’ve entered in specific events in advance to test things out – so I did have ‘theater’ terms events. Taking out the tax_query, I now get everything, but the start_date is not advancing one day as the strtotime() function says it should.
Thoughts?
March 29, 2012 at 10:49 am #17340JonahParticipantHi Mike, not sure what the issue could be with the query, it works fine for me with the start_date/end_date args. Do you have any other code that could be conflicting with this query? Can you paste your full custom query code into http://pastie.org/pastes/new ?
April 3, 2012 at 6:53 am #17524MikeParticipantJonah, here’s the original code:
http://pastie.org/3720843
Strange, but now the tax_query works, but the $currentdate still does not advance with the strtotime() modifier.
Thanks for your help!April 3, 2012 at 9:22 am #17533JonahParticipantWell, glad to hear the tax_query works! Not sure what could be going on with the strtotime() modifier. Maybe a plugin or theme conflict or server/PHP issue?
April 3, 2012 at 9:24 am #17535MikeParticipantThe thing is, that strtotime() works in the $end_date but not $start_date. Any thoughts?
April 3, 2012 at 9:28 am #17537JonahParticipantNo idea Mike, like I said it works fine for me.
May 7, 2012 at 8:54 am #18749Susanne Thiede BarnetParticipantI’m having the same problem with this. I’m letting the user choose a date ranger with the jQuery UI datepicker. Printing out all the values, they all look good. It just seems like how the tribe class parses the date, it automatically overrides it and puts in the current date.
May 7, 2012 at 10:34 am #18759Susanne Thiede BarnetParticipantMaybe this is due to the fact that somewhere in the callstack the property ‘upcoming’ is getting flagged and then returning todays date?
May 7, 2012 at 1:48 pm #18806Susanne Thiede BarnetParticipantI think I was right about my hunch that the eventDisplay property of ‘upcoming’ was nerfing the start_date selector from the tribe_get_events method. I would recommend classifying that as a bug and fixing it in an upcoming release. In the meantime, here is a workaround using WP_QUERY:
Pretty source:
http://pastebin.com/fgpC2ND1Probably pretty ugly source:
query(
array(
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => -1,
‘orderby’ => ‘meta_value’,
‘order’ => ‘ASC’,
‘meta_key’ => ‘_EventStartDate’,
‘meta_query’ => array(
array(
‘key’ => ‘_EventStartDate’,
‘value’ => array( $startDate.’ 00:00:00′, $endDate.’ 23:59:59′),
‘type’ => ‘DATETIME’,
‘compare’ => ‘BETWEEN’
)
)
)
);if ($featured_query->have_posts()) :
while ( $featured_query->have_posts() ) : $featured_query->the_post(); ?>//DO WHATEVER YOU NEED TO DO WITH THE POSTS HERE
<?php else: echo ' Sorry, there are no posts for the selected dates.’; ?>
May 7, 2012 at 1:49 pm #18807Susanne Thiede BarnetParticipantLooks like some of that got cut off. Let me try again:
query(
array(
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => -1,
‘orderby’ => ‘meta_value’,
‘order’ => ‘ASC’,
‘meta_key’ => ‘_EventStartDate’,
‘meta_query’ => array(
array(
‘key’ => ‘_EventStartDate’,
‘value’ => array( $startDate.’ 00:00:00′, $endDate.’ 23:59:59′),
‘type’ => ‘DATETIME’,
‘compare’ => ‘BETWEEN’
)
)
)
);if ($featured_query->have_posts()) :
while ( $featured_query->have_posts() ) : $featured_query->the_post(); ?>//DO WHATEVER YOU NEED TO DO WITH THE POSTS HERE
<?php else: echo ' Sorry, there are no posts for the selected dates.’; ?>
May 15, 2012 at 3:04 pm #19220RobMemberHey Kindra. Thanks for the follow-up here. We can definitely take a look at this for you and I apologize for the delay in responding. If this issue persists would you mind dropping the code you’re using into a pastie.org link (or something similar) so we can see it that way? As it stands there isn’t a very good method for sharing code in the forums beyond that…
Thanks in advance!
May 22, 2012 at 8:33 am #19526Susanne Thiede BarnetParticipantI’ve got a solution up and running. You can see the loop code here:
Here is the filtering in action on a sandbox development installion:
-
AuthorPosts
- The topic ‘Problem with start_date in tribe_get_events in 2.0.4’ is closed to new replies.