• I’m using wp_query to pull events like the below. I use relative dates for different days of the week in the args.

    $loop = new WP_Query(array(
     'post_status' => 'published',
     'post_type' => 'event',
     'ondate' => 'today +1 day',
     'showpastevents' => true,
     'suppress_filters' => false,
      ));

    I’ve played around with my own custom templates and I use eo_get_the_start to get the start date for single events. Everything works great.

    Now I have been noodling this. I know you can call an array of all the recurring event datetimes (and make a list of all dates), and you can get the first and last event. However, I want to target the date of the recurring event as it appears on my event list much like I use eo_get_the_start for non recurring events.

    Is this possible, do you know what I am saying here : ) .

    https://wordpress.org/plugins/event-organiser/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    eo_get_the_start() returns the date of the current event occurrence inside “the Loop”. It also excepts the occurrence ID (and event ID) if you need to specify using a known ID.

    See docs for examples.

    Thread Starter WPWanderer

    (@wpwanderer)

    Thanks. I got this part and making a list of occurrences and the first and last occurrence.

    What I am noodling is trying to use eo_get_the_start to list only the date, for example, the 6th occurrence out of 20. Kind of confusing. From the examples I have seen, you list all occurrence or say these occur from this date to that. What I want to do is match up the date with the date of the occurrence when viewed on a single event.

    Plugin Author Stephen Harris

    (@stephenharris)

    What I want to do is match up the date with the date of the occurrence when viewed on a single event.

    – I think that might be the source of the problem 🙂 – when viewing the single event page, the user is not viewing any particular date for recurring event. It’s one page for all events.

    The workaround is to add the occurrence ID to the event url, e.g. http://yoursite.com/event/my-event?occurrence_id=6 and then on the single event page retrieve $_GET['occurrence_id']. There are better, more involved ways of doing this. I.e. registering a rewrite rule, and getting WordPress to recognise it is a query variable (see http://wordpress.stackexchange.com/questions/41370/using-get-variables-in-the-url/41373#41373 & http://wordpress.stackexchange.com/questions/48487/how-to-retrieve-get-variables-from-rewritten-urls/48489#48489)

    You then obtain that occurrence ID and use it for retrieving the appropriate date.

    This isn’t done in the core plug-in because the page is visible with supplying that ID (and some users group the events). So you may want to keep that in mind.

    There was a snippet provided for doing this automagically, however on recollection there is a technical reason why this won’t work (and so why its not in core). Event Organiser can only reliable modify the link through a filter, which passes only the event ID – making the occurrence ID inaccessible. You can get round this by modifying the templates.

    Thread Starter WPWanderer

    (@wpwanderer)

    Maybe i need to better explain myself : ) .

    On a single event template, for a recurring event, I am trying to post the actual date that occurrence falls on. I can post when the occurrence series starts and ends. And I can list all the occurrences, but I wonder if it is possible to list the occurrence date without specifying the occurrence id for each instance?

    Plugin Author Stephen Harris

    (@stephenharris)

    But my point is which occurrence? When viewing the single event page, there is no particular occurrence being viewed (by default). My earlier post outlines how you might try to capture the occurrence they clicked on to get to the event page, but otherwise, they are not viewing a particular occurrence.

    Thread Starter WPWanderer

    (@wpwanderer)

    Thanks, Stephen. I actually wrote my last response before I saw your alternative option comments. Much appreciated.

    I actually thought of doing something with the url, but was hoping there was some other way. I’ll either do this or something more generic like listing them all.

    Thanks!

    Thread Starter WPWanderer

    (@wpwanderer)

    Question. Is the variable I need to make accessible through get_query_var the occurrence_id or event_id . I’m popping blanks so I just want to make sure I am on the right track.

    Plugin Author Stephen Harris

    (@stephenharris)

    Occurrence ID – the “event id” is effectively the post ID – though, confusingly (and for historical reasons ;), $post->event_id is a copy of $post->occurrence_id. Use $post->occurrence_id.

    But everywhere in the documentation “Event ID” means the (event post type) post ID.

    Thread Starter WPWanderer

    (@wpwanderer)

    Do you have a link on that snippet you mention. I’ve been working on this for awhile now, lol. So, maybe this snippet will shed some light on this. I’ve been trying to access the occurrence_id in every which way (your links and Googling), but it has been a no go.

    Thread Starter WPWanderer

    (@wpwanderer)

    I think I finally got it. I am posting it here just in case it will help anyone who want to do something similar. This would be to append the event id of the occurrence as a query string on a single post.

    function append_query_string( $url, $post ) {
      $eventOccurrence = $post->occurrence_id;
        if ( 'event' == get_post_type( $post ) ) {
            return add_query_arg( 'occurrence' ,$eventOccurrence, $url );
        }
        return $url;
    }
    add_filter( 'post_type_link', 'append_query_string', 10, 2 );
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘echo single date of recurring event’ is closed to new replies.