Home › Forums › Calendar Products › Events Calendar PRO › Inserting a list of events on a page (including recurring events)
- This topic has 6 replies, 2 voices, and was last updated 9 years ago by George.
-
AuthorPosts
-
May 4, 2015 at 5:39 am #960183Benjamin KarschParticipant
Hello there,
since the previous discussions to this topic are quite old (e.g. this one), I’d like to ask this in order to get an answer that fits to the current versions of The Events Calendar (Pro).
I’d like to insert lists of (bookable) events on a few of my WordPress pages. This list should output all events from a certain category, including all the recurring events, and some details like the start and end date of each event. So there should be no distinction between the initial event and its recurring instances. Is there a way to do this and avoid the recurring events to be merged to only one event?
Currently I’m trying to write an override for the events list widget and include this one on the page. That seems like quite a workaround, too, but since the Shortcode plugin isn’t really customizable, I can’t think of any other way to accomplish this integration. So, second question: Is there a cleaner and less destructive way (i.e. keeping the original widget functionality) to integrate my custom events list on a WordPress page?
May 4, 2015 at 10:24 am #960252GeorgeParticipantHey Benjamin,
Though a bit old, the answer Barry gave in that original thread is indeed still the best option here → https://theeventscalendar.com/support/forums/topic/list-the-other-recurring-dates-of-event-on-single-page-template/
Barry linked to some resources for both of the functions he mentioned, which I strongly encourage you to check out.
As for your second question, I’m not quite sure how it differs much from your original one. If you’re able to build the code to show all the data you want on a single page template, you can indeed just re-use that code in a custom widget or something – is that along the lines of what you’re looking for here? I’m really sorry if not – elaborate on your second question in a bit more detail and we can hopefully offer a more helpful answer there! 🙂
Thanks,
GeorgeMay 5, 2015 at 4:07 am #960442Benjamin KarschParticipantHi George,
thanks for the quick reply.
I’m still fumbling with the tribe_get_events function. Can’t I just use the category_name parameter for getting all events from the category with the given name (e.g. ‘Surf-Course’) and all its child categories – much like in WordPress’ get_posts? For now this query doesn’t return any results (although there are certainly events listed in these categories):$events = tribe_get_events( array( 'posts_per_page' => 20, 'start_date' => new DateTime(), 'category_name' => 'Surf-Course' ) );
May 5, 2015 at 4:51 am #960448Benjamin KarschParticipantOk, so far I understand the usage of WP_Query for my purpose. The only thing left to do is find out what the names of the arguments/parameters are!
I need to filter the following:
- only tribe events
- from a certain event category, defined by its slug (e.g. ‘surf-course’)
- start date: today or later
This is my code so far but it’s not working properly yet (surely due to wrong arguments):
$args = array( 'post_type' => 'tribe_events', 'tribe_events_cat_name' => 'surf-course', //? 'eventDisplay' => 'future', //? 'start_date' => new DateTime(), //? 'posts_per_page' => 20 //? ); $events = new WP_Query( $args );
So is there any documentation about which tribe-specific arguments/parameters I can use in combination with WP_Query?
May 5, 2015 at 12:57 pm #960630GeorgeParticipantHey Benjamin,
There are a few tips we can indeed offer here.
First of all, if you’re going to be using any custom events display, it’s best to set ‘eventDisplay’ to just ‘custom’, instead of trying to wrestle with any of the tribe-specific values like ‘upcoming’, ‘past’, etc.
Next, instead of using ‘tribe_events_cat_name’ for the Events Category category name, just use ‘tribe_events_cat’.
Beyond this, there isn’t any Tribe-specific documentation for this function and its arguments because the function itself is just a wrapper for the WP_Query arguments.
Instead of consulting the WordPress Codex article about the get_posts() function, you should consult all the arguments and all their detailed descriptions / examples in the official WP_Query documentation here → https://codex.wordpress.org/Class_Reference/WP_Query
Also, ‘start_date’ can’t be passed to the query directly like you have in your example. It has to be passed within a ‘meta_query’ parameter using the ‘_EventStartDate’ meta key – consult the WP_Query documentation for examples of working with this.
A lot of small details arise even when trying to make customizations that seem simple on the outset, as you can see here, which is why we generally have very tight limitations on customization support to begin with. It can be tricky, but you’re already most of the way here with the arguments you’ve shared in your code examples and such, so I’m sure that with some fiddling around and a thorough examination of the WP_Query class, you can get something workable here.
Be sure to make good backups of your progress along the way!
Best of luck with your customizations,
GeorgegMay 6, 2015 at 2:29 am #960733Benjamin KarschParticipantI actually managed to successfully do the query I described above by looking at the Events Calendar Shortcode plugin.
I’m now using the following code:
$events = get_posts( array( 'post_type' => 'tribe_events', 'posts_per_page' => 20, 'tax_query'=> array( array( 'taxonomy' => 'tribe_events_cat', 'field' => 'slug', 'terms' => 'windsurf-kurse' ) ), 'meta_key' => '_EventEndDate', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => '_EventEndDate', 'value' => date('Y-m-d'), 'compare' => '>=', 'type' => 'DATETIME' ) ) ));
As you can see there’s no WP_Query directly involved.
May 11, 2015 at 7:40 am #961791GeorgeParticipantGlad to see it Benjamin! Best of luck with your site. And remember, both tribe_get_events() and get_posts() do just “wrap” the main WP_Query class, so even through you’re not calling it directly, you should still be able to find that WP_Query documentation helpful if you want to further customize your queries and such.
Be sure to keep good backups of all custom code like this – and of your site in general!
Cheers 🙂
George -
AuthorPosts
- The topic ‘Inserting a list of events on a page (including recurring events)’ is closed to new replies.