How do I list out a number of events based on different criteria in a template?

Home Forums Calendar Products Events Calendar PRO How do I list out a number of events based on different criteria in a template?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1446272
    Joakim
    Participant

    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.

    #1446361
    Joakim
    Participant

    I’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 );

    #1446528
    Joakim
    Participant

    Somehow 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 );

    #1447322
    Joakim
    Participant

    Anyone?

    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.

    • This reply was modified 6 years, 3 months ago by Joakim.
    • This reply was modified 6 years, 3 months ago by Joakim.
    • This reply was modified 6 years, 3 months ago by Joakim.
    • This reply was modified 6 years, 3 months ago by Joakim.
    #1448189
    Victor
    Keymaster

    Hi 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,
    Victor

    #1450387
    Joakim
    Participant

    Thank you!

    #1451200
    Victor
    Keymaster

    You 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

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘How do I list out a number of events based on different criteria in a template?’ is closed to new replies.