I am using the pro version of events calendar by modern tribe on the theatre site.
I am trying to find a way to isolate events that happen on the weekend with a post query. I think it would work similar to this – http://pastebin.com/9BhbUm7R
but I am not sure how to tell it to only show saturday and sunday each week.
I will also need to try to show only events that are starting this week and ending this week.
Kyle answers:
PHP's strtotime() function actually accepts parameters like that:
date("Y-m-d", strtotime("next Saturday"));
date("Y-m-d", strtotime("next Sunday"));
Kyle comments:
For this week, you could do
date("Y-m-d", time() );
date("Y-m-d", strtotime("next Sunday"));
Amanda comments:
This is working for me
$saturday = date("Y-m-d", strtotime("next Saturday"));
$sunday = date("Y-m-d", strtotime("next Sunday"));
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date' => $saturday,
'end_date' => $sunday,
'posts_per_page'=>10
foreach($events as $post) {
setup_postdata($post);
) );
Do you know how I can isolate starting this week (only new productions)? and Ending this week?
Kyle comments:
Do you mean 'this week' as in the next 7 days, or from now until Sunday, or something like that?
Amanda comments:
I think it would be from - from now until Sunday
So if the user hit the site on a wednesday they would get Wednesday to Sunday's new productions
Kyle comments:
Okay, your original code was pretty close. Try this:
$today= date("Y-m-d");
$sunday = date("Y-m-d", strtotime("next Sunday"));
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date' => $today,
'end_date' => $sunday,
'posts_per_page'=>10
foreach($events as $post) {
setup_postdata($post);
) );
Amanda comments:
That will work but I believe it will pull all events not just the ones that start in that week (new - 1st week of show).
And the same would go for ending (closing - not available after this week).
Kyle comments:
I'm not sure I understand, are you trying to pull 'events that start this week' and 'events that end this week'?
Amanda comments:
thats correct
Kyle comments:
You'll probably have to use meta_query instead of the tribe filters like below. Just replace the key for end day. This is untested, but should be close:
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_EventStartDate',
'value' => date("Y-m-d", strtotime("next Saturday")),
'compare' => '<',
'type' => 'date'
),
array(
'key' => '_EventStartDate',
'value' => date("Y-m-d"),
'compare' => '>',
'type' => 'date'
)
)
Amanda comments:
Ok, I am a little lost on this one. I'm not getting anything to display. I'm not sure if I am not adding it correctly.
Or it's just not outputting the items
Kyle comments:
Is this what your's looks like
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'posts_per_page'=>10,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_EventStartDate',
'value' => date("Y-m-d", strtotime("next Saturday")),
'compare' => '<',
'type' => 'date'
),
array(
'key' => '_EventStartDate',
'value' => date("Y-m-d"),
'compare' => '>',
'type' => 'date'
)
)));
If that still fails try reversing the two < > points
Amanda comments:
I must of stuffed it up previously. I am showing data now.
But not the right data it's showing me events that have already started and not showing the event I set up today which should fall under the Opening this week.
Kyle comments:
Did you try reversing the < >
Amanda comments:
Yes, I got 2 productions on the original code and 3 productions on the reversed. All opening before this week and not showing my event for today.
Kyle comments:
I can run live tests on my local environment in the morning my time to get it working right
Kyle comments:
Also, try switching from tribe_get_posts to new WP_Query, and remove the eventdisplay argument
Kyle comments:
Did you try implementing that?
Amanda comments:
I didn't know how to do it.
Amanda comments:
I wasn't sure how to add the query and to get it to display
Kyle comments:
It would look like this http://pastie.org/8870438
Amanda comments:
this should still output the events shouldn't it?
foreach($events as $post) {
setup_postdata($post);
Kyle comments:
You can, or you can use a while() function. For testing that should be fine. I can help polish it up in the end when it is displaying what we want.
Amanda comments:
it's not showing anything. I'm sure I am doing something wrong.
Unfortunately I have the site currently on localhost so I can't show you the pages.
Here is the code for the content area.
http://pastebin.com/7iK8dAew
Kyle comments:
No problem, we'll get it. Give me a few minutes to write this up onto my test site and I'll see what I can do.
Kyle comments:
This should do the trick http://pastie.org/8877923#6-7,12
Amanda comments:
Thanks
I am getting 4 posts but they are all shows that opened in february and I am also getting a double up one of the productions.
Kyle comments:
I'm wondering if there is something strange going on with the time in your test environment, this is working perfectly on my site. If I set the time for even 5 minutes ago or 12:01am Monday it won't show, but shows everything in between.
Kyle comments:
Do you have a live environment you can test on?
Arnav Joy answers:
can you explain your requirement
Amanda comments:
It is for a theatre website with events in the area. The client wants it to pull events for these links:
- What's on this weekend
- Starting this week
- Ending this week
I need to show the event posts that fall into those
Arnav Joy comments:
try this
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date' =>date("Y-m-d", strtotime("last monday")),
'end_date' => date("Y-m-d", strtotime("next friday"))
) );