Hi there,
I have set up a website which imports events from a remote ICS file. The title of the events are pulled from the “SUMMARY” value which is used by the client to show the event category and location city in the following format “Event Category - City
“.
The permalink subsequently becomes /event-category-city
, but because that’s hardly unique, the permalinks are being numbered /event-category-city-1
etc.
Is it possible to add the date of the event to the permalink so, say for an event scheduled to run on 15 May 2017, we end up with something like /event-category-city-15052017
?
Alternatively, is it possible to add the value of another field in the ICS file to the permalink?
Cheers
Jamie
Jamie McCormack
I’ve not tested this, but perhaps the post straightforward way of doing this would be to update the post_name
after the event is inserted:
add_action( 'eventorganiser_ical_sync_event_inserted', function( $event_id, $event, $feed_id ) {
wp_update_post( array(
'ID' => $event_id,
'post_name' => sanitize_title( $event['post_title'] ) . '-' . eo_get_schedule_start( 'Y-d-m', $event_id );
));
}, 10, 3 );
Stephen Harris
Thank you Stephen,
I was about to try your suggestion when it turned out the client wants the permalinks to be completely different.
Sorry to bug you like this, but is there a solution for the following scenario?:
The imported iCal file will have a new variable added for the event ID, which is determined at the client’s end. Let’s say the new variable in the iCal file is labelled “EVENTID”.
Currently, the post title is set using the “SUMMARY” variable from the iCal file, which we don’t want to change.
Is it possible to use EVENTID for the permalink without changing the post title?
For example:
The iCal file is imported where SUMMARY = “Event One” and EVENTID = “523”.
When imported, the post title will be “Event One”, but the permalink will be “http://website.com/event523”
I hope that makes sense.
Cheers
Jamie
Jamie McCormack
Hi Jamie,
That’s possible. Try the following:
<?php
// Parse the EVENTID attribute (it will otherwise be ignored)
add_action( 'eventorganiser_ical_property_eventid', function( $value, $modifiers, $ical_parser ) {
$ical_parser->current_event['eventid'] = (int) $value;
}, 10, 3 );
// The eventid should not be available in $event
add_action( 'eventorganiser_ical_sync_event_inserted', function( $event_id, $event, $feed_id ) {
wp_update_post( array(
'ID' => $event_id,
'post_name' => sanitize_title( $event['post_title'] ) . $event['eventid'];
));
}, 10, 3 );
Stephen Harris
Thank you Stephen.
I am unable to try that at the moment, but in the mean time I just need to ask one question…
By using your suggestion, would I then be able to change the Event (single) permalink in ‘Event Settings’ settings to be: events/event[event_id]
Cheers,
Jamie
Jamie McCormack
No. Incidentally, I misread your client’s requirements and you would instead want to set:
'post_name' => $event['eventid'];
The permalink settings should be set to: event/
. This gives an URL of the form:
yoursite.com/event/523*
which isn’t quite what you asked for. You could have yoursite.com/events/event523
relatively easily – but yoursite.com/event523
would involve a bit more work.
*As an aside – this only works for events imported via iCal. Events created in WordPress will be yoursite.com/event/<slug>
– essentially you’re just setting the slug to the ID of the event as specified in the iCal feed.
Stephen Harris
Thanks again Stephen.
As always, your support is invaluable.
Your solution of yoursite.com/event/523
will be fine. It’s basically so my client can set links to events, based on the event ID, in their emails without having to copy the URL from the site like they currently do now. Sometimes the event title changes and it voids the original link they would’ve sent.
I will let you know how I get on.
Cheers
Jamie
Jamie McCormack