Selecting events by event ID?

This topic contains 4 replies, has 2 voices, and was last updated by  Stephen Harris 10 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12746

    On my site I allow users to “bookmark” upcoming events.

    They have a page they can view that would show them all these saved events.

    How do I select events based on the event ID’s ?

    Thanks

    Robb

    VERB Interactive
    #12757

    Hi Robb,

    These bookmarked events – in the case of recurring events do they book mark the entire event or specific occurrences? If the they are bookmarking an entire event series, or if you only have single events, you can simply use the post__in argument with the event (post) ID:

    $events = eo_get_events(array(
         'post__in' => array( ... ), //array of event (post) IDs
    ));

    Otherwise for specific occurrences you can use event_occurrence__in argument with the event’s occurrence ID

    $events = eo_get_events(array(
         'event_occurrence__in' => array( ... ), //array of event (occurrence) IDs
    ));

    Both can be used with WP_Query or get_posts(), if you prefer, but you will need to set post_type to event and supress_filters to false. (eo_get_events() is a thin wrapper for get_posts()).

    Stephen Harris
    #12841

    Thanks for writing back.

    How do I write to get events by id (post_id) but not get all the occurrences?

    I tried:
    group_event_by -> ‘ID’
    ‘showrepeats’ => 0

    Both of which do not seem to do anything actually having traced them in the code.

    Thanks for your time.

    Robb

    VERB Interactive
    #12842

    Got it.

    ‘group_events_by’ => ‘series

    So you can use:

    $events = new WP_Query( array(
      'post_type'=> 'event',
      'post__in' => $arrayOfIds,
      'suppress_filters'=>FALSE,
      'numberposts'=>-1,
      'orderby'=> 'eventstart',
      'order'=> 'ASC',
      'showrepeats'=>1,
      'group_events_by'=>'series',
      'showpastevents'=>TRUE
       )
    );

    Or…

    $events = eo_get_events(
      array(
        'post__in' => $arrayOfIds,
        'group_events_by'=>'series'
      )
    );
    VERB Interactive
    #12843

    Hi Robb,

    Yes you can use both. Though the form returns a WP_Query instance and the latter an array of post objects. Which you prefer to use is largely down to personal preference, and the fact that tehre are some functions (e.g. the_content()) which have to be used ‘inside the loop’ (i.e. using WP_Query). But there are ways around that: http://stephenharris.info/get-post-content-by-id/

    Stephen Harris
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.