Home › Forums › Calendar Products › Events Calendar PRO › Create a 'All Events Next Month" Page
- This topic has 12 replies, 2 voices, and was last updated 10 years, 6 months ago by
Brook.
-
AuthorPosts
-
October 26, 2015 at 10:24 am #1018000
Ash
ParticipantApologies if this is a dumb question, but I’m looking for the code to add to my template page that will return all events for next month (as an example). I’ve been through the docs and while I’m sure it must be there, I’m buggered if I can find it.
Any help/guidance appreciated.
Thanks,
Ash
October 26, 2015 at 11:46 am #1018069Brook
ParticipantHowdy Ash,
I would love to help you with this. There are a couple of ways to do this depending on your needs:
- Use shortcodes. The can even be embedded with PHP using do_shortcode(). We have two PRO Shortcodes, one that embeds a copy of the list widgets, and another that embeds the minical widget.
- Use tribe_get_events(). That tutorial walks you through how to use this function to retrieve a set of events within a period of time. Shows you how you can echo them, and so forth.
If you are not trying to embed this list using PHP, then still check out the shortcodes. The minical by default will only show the current month’s events.
Does that all make sense? Will that work for you?
Cheers!
– Brook
October 26, 2015 at 1:49 pm #1018677Ash
ParticipantThanks for the quick reply. I tried using the short code, but couldn’t see how to limit to ‘next month’. Did I miss that?
October 26, 2015 at 11:49 pm #1018773Brook
ParticipantOh I am sorry, for some reason I was thinking you wanted to show the current months events, not next. The minical by default shows the current month, so I was thinking it might be perfect.
In your case the simplest way to do what you want would be to use tribe_get_events(), as the shortcodes do not support specifying which month to view. Technically it would be possible to duplicate the shortcode, rename it, and add in the ability to limit it to a given month. But this will involve a lot of time and development. If you instead use tribe_get_events() it will be much quicker, particularly if you start with the example code in that tutorial for retrieving and displaying a months worth of events!
Does that answer all of your questions?
Cheers!
– Brook
October 27, 2015 at 4:15 am #1018791Ash
ParticipantThanks,
I’m now creating the loop using get_events. How do I make it query next week, month, etc?
October 27, 2015 at 10:22 am #1018961Brook
ParticipantCheckout this example. You would specify a date range as in that example. If you want next month for example, start date will 2015-10-01 and end will be 2015-10-30. If you need to dynamically calculate what the next month is and when it begins/ends, checkout these helpful posts on StackOverflow and the PHP documentation on strtotime(). You can use this to calculate the next week, next month, etc.
Does that all make sense?
Cheers!
– Brook
October 27, 2015 at 11:42 am #1019007Ash
ParticipantHi,
I’m struggling with creating this rule to apply dynamically.
This just break the page:
<?php $query_date = 'now'; // Ensure the global $post variable is in scope global $post; // Retrieve all events in coming month $events = tribe_get_events( array( 'eventDisplay' => 'custom', 'start_date' => 'new DateTime()', 'end_date' => 'echo date('Y-m-t', strtotime($query_date));' ) );I assume my syntax is wrong?
October 28, 2015 at 12:39 pm #1019495Brook
ParticipantHowdy Ash,
Your syntax isn’t quite perfect. You can not put an echo in there, and you don’t want to wraps your objects in single quotes or else they will be treated as strings.
$query_date = strtotime('+1 month'); $events = tribe_get_events( array( 'eventDisplay' => 'custom', 'start_date' => date('Y-m-d', $query_date), 'end_date' => date('Y-m-t', $query_date) // This selects the end of MONTH ) ); var_dump($events);This example will give you next months events. Next week is going to be trickier though as you will have to calculate the beginning end of the week, based on your local format such as when the week starts. T
his probably is not a very easy thing to build, and might require you to learn a goodly bit more PHP to get there. 🙁 If it is starting to sound too daunting, you might be interested in suggesting this as a feature: UserVoice (feature suggestion page for The Events Calendar) . Perhaps if you suggested “Add start/end date arguments to shortcodes” it would be something other people would be interested in, and we could add it to a future version of The Events Calendar. Or, you might be interested in hiring a dev to build this on your behalf. It might take someone experienced a couple hours or so.
Does that help clarify the code and such?
Cheers!
– Brook
October 29, 2015 at 3:59 am #1019672Ash
ParticipantBrook,
Thanks – I think I’m just about there and can adapt this piece of code to achieve what I need.
It does seem odd that this sort of function isn’t included as core, though. Most other event plugins I’ve used do, often called with simple shortcodes. Is there a reason for the omission?
October 29, 2015 at 6:54 am #1019699Ash
ParticipantI’m having issues with the other strtotime functions. Plus one month, two months, etc seems to work OK, but using plus week, doesn’t seem to be calculating quite right, returning events that are not in scope. Example is this query:
// Retrieve all events in coming two weeks $now = strtotime('now'); $query_date = strtotime('+2 week'); $events = tribe_get_events( array( 'eventDisplay' => 'custom', 'start_date' => date($now), 'end_date' => date('Y-m-t', $query_date) ) );This should return events in the range today (29 Oct) to 12 Nov, of which there are none. Yet I have an event with a date of 19 Nov that is being returned.
Is there a further rule I need to add in here?
October 29, 2015 at 1:00 pm #1020015Brook
ParticipantHowdy Ash,
Most other event plugins I’ve used do, often called with simple shortcodes. Is there a reason for the omission?
We do have shortcodes, they just don’t have date limiters. You are actually the first I can recall desiring this particular feature out of the thousands I’ve helped. Though I would not be surprised if a few others wanted it as well, they just did not think to voice it.
Pay special attention to your date formats:
'start_date' => date($now), 'end_date' => date('Y-m-t', $query_date)The start date has no date format. It is ideal to specify it. The end date is Y-m-t. ‘t’ is the last day of the month for your query date, so it would be all events from now til Nov 30th (the month that is +2 weeks away). You probably want to use ‘d’.
Cheers!
– Brook
October 30, 2015 at 3:00 am #1020172Ash
ParticipantBrook,
That makes complete sense – thank you. I’m surprised that more folks haven’t requested this type of feature – perhaps your plugin attracts more seasoned developers than me!
I think I have all I need, so I’ll mark this as resolved. Many thanks,
Ash
November 2, 2015 at 1:58 am #1020645Brook
ParticipantYou are very welcome!
We are always interested in feedback from folks who aren’t as “seasoned” as you say. If you would like to see that become a feature, please don’t forget to suggest it on our feature tracker. That way other folks can vote their support as well. UserVoice (feature suggestion page for The Events Calendar)
Cheers!
– Brook
-
AuthorPosts
- The topic ‘Create a 'All Events Next Month" Page’ is closed to new replies.
