WordPress.org

Support

Support » Plugins and Hacks » Event Organiser » [Resolved] [Plugin: Event Organiser] Get next reoccurrences only?

[Resolved] [Plugin: Event Organiser] Get next reoccurrences only?

  • First off, thank you Stephen for a fantastic, intuitive plugin.

    Quick question, perhaps this is obvious and I’m sorry if it is — but is there any way to return the next occurrence only of an event when displaying a list of upcoming events using eo_get_events?

    The numberposts argument is helpful in limiting the total number of events displayed, but say I have a daily, weekly, and monthly recurring event and want to list the next of each, how could I do this?

    Thanks.

    http://wordpress.org/extend/plugins/event-organiser/

Viewing 5 replies - 1 through 5 (of 5 total)
  • So (currently undocumented) is a property 'group_events_by' which can take the value 'series'. This will only show the first matching occurrence of an event, to that query. That means if you search for all events (past and present) then you’ll get the first occurrence of each event. If you limit your search to non-past events, then you’ll get a list of the next occurrences of events;

    Gets a list of all events (next occurrence only)

    eo_get_events(
      'numberposts'     => -1,
      'group_events_by' => 'series',
      'showpastevents' => false,
    )

    If you want a specific event’s next occurrence, you can use the 'event_series' (again undocumented). This takes the post ID of the event.

    eo_get_events(
      'numberposts'     => -1,
      'group_events_by' => 'series',
      'event_series'=>5
      'showpastevents' => false,
    )

    If you just need the date, you may want to use eo_get_next_occurrence() instead.

    Thanks! 'group_events_by' => 'series' does exactly what I needed.

    Related followup question — is there any easy way to manipulate the query on event taxonomy pages (taxonomy-event-category.php, etc) with Event-Organiser-specific arguments? e.g. using group_events_by as you describe above, or a combination of event_start_after & event_end_before to limit an archive to, say, a year either side of today?

    Never mind, solved my own problem! You can manipulate the query string on event taxonomy pages in the same way that you’d do it on any other archive page.

    Event-Organiser-specific arguments are accepted and understood fine on these templates — I’m not sure why I thought they weren’t.

    I’ve inserted the following code before the loop on taxonomy-event-category.php and taxonomy-event-venue.php, and it behaves as expected.

    global $query_string;
    // Newest events first, show events for next 12 weeks and last 12 months
    query_posts( $query_string . '&orderby=eventstart&order=DESC&event_start_before=+12 week&event_start_after=-12 month' );

    Thanks again for all your work on the plugin – easily the best WordPress Events plugin I’ve used.

    Yup, Event-Organiser-specific arguments are understood by WP_Query.

    But please don’t use query_posts! . It often breaks things, and is incredibly inefficient, and there’s talk of depreciating it.

    Instead, hook into pre_get_posts (make it priority 9 – anything below 10, to be sure that the plug-in runs its checks after you – but actually, I think it doesn’t matter…).

    You’ll want to make sure the query ‘is the main one’ (see linked WPSE answer for more details 🙂 )

    Thanks for the heads-up on pre_get_posts. I’ve adjusted my code on this project and will use this in future instead of query_posts.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] [Plugin: Event Organiser] Get next reoccurrences only?’ is closed to new replies.
Skip to toolbar