Need help with get_posts and recurring events

Home Forums Calendar Products Events Calendar PRO Need help with get_posts and recurring events

  • This topic has 3 replies, 2 voices, and was last updated 6 years ago by Joakim.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1514627
    Joakim
    Participant

    I’m using get_posts to retrieve events on a page like this:

    $posts = get_posts(array(
    'numberposts' => 8,
    'post_type' => array('tribe_events'),
    'meta_query' => array(
    'relation' => 'AND',
    array(
    'key' => 'forsidesak',
    'value' => 1,
    'compare' => '==',
    ),
    array(
    'key' => '_EventStartDate',
    'value' => $today,
    'compare' => '>=',
    ),
    ),
    'orderby' => '_EventStartDate',
    'order' => 'ASC',
    ));

    For recurring events I need to display only the first event. How can I do that here? Is it possible to check if an event is part of a series of recurring events, get the first date of the series, get the start date of the event we’re fetching, and if the two start dates are different, don’t fetch it?

    #1516266
    Victor
    Keymaster

    Hi Joakim!

    Thanks for getting in touch with us!

    First, please let me note that we are fairly limited in how much support we can give for custom development questions like that.

    That said, we always like helping out and at least point users into the right direction as much possible.

    For custom event queries I’d recommend you take a look at the following article about the tribe_get_events() helper function > https://theeventscalendar.com/knowledgebase/using-tribe_get_events/

    In recurring events, every recurring instance is a child event (child post) of the main event. You can also use the tribe_is_recurring_event() function to see if an event is recurring.

    You will find that and other helpful functions in /wp-content/plugins/events-calendar-pro/src/functions/template-tags/general.php

    I hope that helps you get started. Let me know if any follow up questions.

    Best,
    Victor

    #1516785
    Joakim
    Participant

    Thanks! Your answer led me to this very simple solution; by adding 'post_parent' => 0 to the parametres.

    • This reply was modified 6 years ago by Joakim.
    #1517331
    Victor
    Keymaster

    Right on Joakim! Glad to know you could accomplish that 🙂

    Thanks for following up to let us know.

    I’ll go ahead and close this thread now, but feel free to open a new topic if anything comes up and we’ll be happy to help.

    Cheers,
    Victor

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Need help with get_posts and recurring events’ is closed to new replies.