Home › Forums › Calendar Products › Events Calendar PRO › Get link for next event in series
- This topic has 16 replies, 3 voices, and was last updated 8 years, 11 months ago by
Steve.
-
AuthorPosts
-
May 10, 2017 at 9:24 am #1281709
Steve
ParticipantI created a recurring event starting last Weds, running every Weds for 6 weeks. Using custom fields I’ve selected that event to feature on the home page. Up until the first instance, the link is fine, it was something like this:
http://example.com/event/test-event-weds-6-weeks/2017-05-03/
However, once the first event passed the permalink returned by both permalink() and tribe_get_event_link() is still as above – and the link shows ‘event passed’.
If I manually hack the link to this:
http://example.com/event/test-event-weds-6-weeks/2017-05-10/
The next events displays fine.
I must be missing something obvious. How can I get the link to the next event in a series?
May 11, 2017 at 12:46 pm #1282528Andras
KeymasterHello again Steve,
Thanks for reaching out!
I didn’t find any function that would directly give you the url of the next event in the recurring series, but I believe this function should help you with your question:
tribe_get_upcoming_recurring_event_id_from_urlLet me know.
Cheers,
AndrasMay 12, 2017 at 4:51 am #1282866Steve
ParticipantThanks but it doesn’t really help. Here’s what’s happening:
- tribe_all_occurrences_link() returns the /all/ link for the event
- Passing that to tribe_get_upcoming_recurring_event_id_from_url() returns an ID 6829
- Passing that to tribe_get_event_link() returns the URL for the event on 2017-05-10 – two days ago, ‘event past’
- If I edit the post 6829, a notice says ‘You are currently editing all events in a recurring series.’ However, the permalink given is for 2017-05-10.
- If I look in the database at 6829, it has a parent 6822 (which has parent 0)
- If I edit 6822, it also says I’m editing all in the series, but the permalink is 2017-05-03 (the first in the series)
What I need is the NEXT event in the series, based on today going forward. Seems pretty basic? Not sure why there’s a need for such convolution (which doesn’t even work).
May 12, 2017 at 8:31 am #1282988Andras
KeymasterHey Steve,
I am trying to help you out here, but please note, I am limited in supporting customizations. Per our terms and conditions we support features of the plugins and although we try to help get you started on customizations for the most part you are going to have to take it on to complete.
The issue is definitely curious, I would expect it to return the next one in the future.
A bit of explanation on editing a recurring series.
If you want to edit an event in the series then you have two choices: either you edit the whole series (as it was in your case – that’s what also happens when you look at an event on the front-end and you click “Edit event” in the admin bar), or you can edit that single instance, but for that you need to break it out from the series, which means that you will have a recurring event before this event, and another recurring event after this event. This latter you can only do in the backend.
So what you wrote above – the last 3 points – is how it is supposed to be / work.
Please give me some time, I will check with the team if anyone has an idea how this could be done.
Thanks for your patience.
Andras
May 12, 2017 at 9:01 am #1283016Steve
ParticipantTo be clear, my mentioning of ‘editing’ the events was merely to highlight what each post ID I’m mentioning refers to, how that particular post is seen by the plugin. I’m not really concerned with editing them here. I’m just surprised there’s not a function to get the link to the next upcoming event in a series.
I’ve gone over to a vanilla install of the latest WP, with only EC and EC Pro plugins activated. I’m running custom code using a child of the 2015 theme. Hopefully this can rule out clashes with other custom code.
I’ve created the same event series – starting on 2017-05-03, running every Weds until the end of June. The ID of the ‘parent event’ (with post_parent = 0) is 108.
Here’s the test code:
$parent_event_id = 108; $event_all_link = tribe_all_occurences_link( $parent_event_id ); echo $event_all_link . '<br>'; $upcoming_event_id = tribe_get_upcoming_recurring_event_id_from_url( $event_all_link ); echo $upcoming_event_id . '<br>';I’m getting this:
http://wps.dev/event/test-recurring-event/all/
So currently no ID is being returned by tribe_get_upcoming_recurring_event_id_from_url().
May 15, 2017 at 7:52 am #1283904Andras
KeymasterHey Steve,
One of my team mates was kind enough to take a look at this and came up with this snippet.
<?php$parent_id = 1823;
$next_event_link = '';// if parent is past let's look for the next child.
if ( tribe_is_past_event ( $parent_id ) ) {// retrieve the next child event
$next_event = tribe_get_events( array(
'posts_per_page' => 1,
'post_parent' => $parent_id
) );// maybe there's no upcoming event
if ( !empty($next_event) ) {$next_event_link = tribe_get_event_link( $next_event[0]->ID );
echo $next_event_link;
}} else {
$next_event_link = tribe_get_event_link( $parent_id );
}Let me know if this helps you move forward.
Cheers,
AndrasMay 15, 2017 at 11:20 am #1284002Steve
ParticipantThanks. That snippet only works if the next upcoming event happens to be the 2nd in the whole series. However, it seems to work with the addition of a start_date parameter to the query:
$next_event = tribe_get_events( array( 'posts_per_page' => 1, 'post_parent' => $parent_id, 'start_date' => date( 'Y-m-d H:i:s' ) ));So basically it’s necessary to ‘manually’ query for the next upcoming event in a series. Frankly I’m astonished that such (presumably) frequently-used functionality doesn’t have a function, or at least a parameter to manage it in tribe_get_event_link().
May 16, 2017 at 12:50 am #1284249Andras
KeymasterThat’s a great adjustment, indeed it looks like that’s needed. You should be able to query for today’s date and set the comparison not to equal but to smaller than.
Will that do the trick?
Andras
May 17, 2017 at 4:26 am #1284831Steve
ParticipantAm I misunderstanding the start_date parameter? I copied from the example here:
Which says: ‘The above code simply retrieves a list of upcoming events.’
May 17, 2017 at 5:45 am #1284847Andras
KeymasterHey Steve,
I don’t know how you understand that snippet, but here’s how I understand it:
`// Retrieve the next 5 upcoming events
$events = tribe_get_events( array(
‘posts_per_page’ => 5,
‘start_date’ => date( ‘Y-m-d H:i:s’ )
) );`“Get the events which have a start_date of <span style=”text-decoration: underline;”>today</span> formatted like ‘2017-05-17 14:44:00’ and list 5 per page.”
Does this clarify?
Andras
May 17, 2017 at 6:17 am #1284854Steve
ParticipantI assumed from the description in the docs that start_date means ‘get events whose start date is on this date or later’. The docs are pretty clear: ‘The above code simply retrieves a list of upcoming events’ (with start_date set to today).
Testing in my test installation this appears to be the case. However, posts_per_page doesn’t seem to work. At least, I have one recurring event with many upcoming instances. If I run that code it only returns one instance. That instance is the one that is ‘start_date or later’, but there’s only one.
However, for my practical purposes, I only need to output the next upcoming instance of one event. So there seems to be an issue there (either in lack of clarity of docs, or in the functionality), but it doesn’t affect me right now.
I’m not clear about your comment: ‘You should be able to query for today’s date and set the comparison not to equal but to smaller than.’ Which parameter controls the comparison? Sounds like a reference to the meta_query parameter. Is it a case of using meta_query explicity to use the comparison operator, instead of using start_date (which I presume is a shortcut for meta_query)?
May 18, 2017 at 8:10 am #1285534Andras
KeymasterYeah, you are right, I left out the “start date is today <span style=”text-decoration: underline;”>or later</span>” as that should be the case.
On the comparison part I was thinking about a code like this:
$args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'movie_genre', 'field' => 'slug', 'terms' => array( 'action', 'comedy' ), ), array( 'taxonomy' => 'actor', 'field' => 'term_id', 'terms' => array( 103, 115, 206 ), 'operator' => 'NOT IN', ), ), ); $query = new WP_Query( $args );
And found these 2 articles that could provide you with more information:
https://theeventscalendar.com/knowledgebase/custom-event-queries/
https://codex.wordpress.org/Class_Reference/WP_Query
Does this help you move forward?
A.
May 18, 2017 at 8:26 am #1285546Steve
ParticipantWell as I said above (https://theeventscalendar.com/support/forums/topic/get-link-for-next-event-in-series/#post-1284002), I’ve got code that seems to work for me with start_date. I just made a comment there that I’m surprised there’s no function to do this (get the next upcoming event). And then I was thrown by your next comment(s), which suggested I was missing something. But I’m not sure I am?
May 18, 2017 at 8:36 am #1285556Andras
KeymasterOh, I’m sorry, I must have mis-read something, it wasn’t clear to me that you managed to get it working. If you did, that is awesome! Congrats for that! Most probably you are not missing anything.
Is there still something regarding this topic that I can help you with or can we close this topic as resolved?
Andras
May 18, 2017 at 8:40 am #1285558Steve
ParticipantAll OK I think, cheers.
-
AuthorPosts
- The topic ‘Get link for next event in series’ is closed to new replies.
