Home › Forums › Calendar Products › Events Calendar PRO › How do I list out a number of events based on different criteria in a template?
- This topic has 7 replies, 2 voices, and was last updated 6 years, 3 months ago by Joakim.
-
AuthorPosts
-
February 7, 2018 at 7:21 am #1446272JoakimParticipant
For instance, I’ve created a customised template for a single event. On the bottom I’m going to list the next 4 events in the same category (or 4 next events with the same venue, same date, same ACF-field value, etc.).
Also, I need to control the output so I can place the info inside relevant html-tags.
February 7, 2018 at 8:29 am #1446361JoakimParticipantI’m able to list events with a regular wp_query, but how do I list only events within a certain event category?
I’ve tried using ‘category_name’, but that doesn’t work:
// WP_Query arguments
$args = array(
‘post_type’ => ‘tribe_events’,
‘category_name’ => ‘movies’,
‘posts_per_page’ => ‘4’,
‘orderby’ => ‘date’,
);// The Query
$query = new WP_Query( $args );February 7, 2018 at 9:18 am #1446528JoakimParticipantSomehow I found it out. I’m supposed to use ‘tribe_events_cat’.
I think we should be able to find a list of event metadata somewhere in the documentation, but I couldn’t find it. It’s quite possible I suck at searching.
How do I make sure only events with start date after today (or a custom date) gets queried? Here’s my wp_query so far:
// WP_Query arguments
$args = array(
‘post_type’ => ‘tribe_events’,
‘tribe_events_cat’ => ‘movies’,
‘posts_per_page’ => ‘4’,
‘orderby’ => ‘_EventStartDate’,
‘order’ => ‘ASC’,
);// The Query
$query = new WP_Query( $args );February 8, 2018 at 1:32 am #1447322JoakimParticipantAnyone?
Solved that last one myself too.
Get today’s date like this: $today = date(“Y-m-d”);
Then update the WP Query’s args like this:
$args = array(
'post_type' => array('tribe_events'),
'meta_query' => array(
array(
'key' => '_EventStartDate',
'value' => $today,
'compare' => '>=',
)
),
'tribe_events_cat' => $main_category,
'posts_per_page' => '4',
'orderby' => '_EventStartDate',
'order' => 'ASC',
);>
is supposed to be ‘>’ obviously.February 8, 2018 at 12:14 pm #1448189VictorKeymasterHi Joakim!
Thanks for reaching out to us!
First, let me apologise for the delay in getting back to you. We’ve been out on our annual team trip and we are slowly getting back to normal response times.
It’s great you could achieve what you were looking for with the tribe_events_cat and today’s date. As a reference, let me point you to the following article that will get you started with using the tribe_get_events() helper function > https://theeventscalendar.com/knowledgebase/using-tribe_get_events/
Is there anything else I can help you with? Let me know about it.
Best,
VictorFebruary 12, 2018 at 1:14 am #1450387JoakimParticipantThank you!
February 12, 2018 at 6:00 pm #1451200VictorKeymasterYou are welcome Joakim!
As you marked this resolved, I’ll go ahead and close it. But don’t hesitate to open a new topic if anything comes up and we’ll be happy to help.
Cheers,
Victor -
AuthorPosts
- The topic ‘How do I list out a number of events based on different criteria in a template?’ is closed to new replies.