Allow event slug to be specified
-
I wrote a standalone script to import events from another site.
The events are for musicians in a bar. Many of the musicians play regularly.I use EM_Event::save() after creating a new EM_Event() object and populating some of the values.
$EM_Event = new EM_Event(); $EM_Event->event_name = $event_title; // Append date to event so that the url of repeated events look better. $event_slug = sanitize_title($event_title.' '.$event_start_date); $EM_Event->event_slug = $event_slug; $EM_Event->post_name = $EM_Event->event_slug; $EM_Event->post_content = $event_description; $EM_Event->event_owner = $author_id; $EM_Event->location_id = $location_id; $EM_Event->event_start_date = $event_start_date; $EM_Event->event_end_date = $event_end_date; $EM_Event->event_start_time = $event_start_time; $EM_Event->event_end_time = $event_end_time; $EM_Event->start = strtotime($EM_Event->event_start_date.' '.$EM_Event->event_start_time); $EM_Event->end = strtotime($EM_Event->event_end_date.' '.$EM_Event->event_end_time);
Unfortunately, $EM_Event->event_name is sent to wp_insert_post() [as ‘post_title’] but $EM_Event->post_name isn’t.
This results in event slugs like Band-name, Band-name-2, Band-name-3 etc.
I would like to have Band-name-2017-10-01 (name – date).Would it be possible to send post_name to wp_insert_post()?
Suggested patch:
--- em-event.orig.php 2017-09-27 10:01:24.296281200 +0100 +++ em-event.php 2017-09-27 12:19:27.388067700 +0100 @@ -757,6 +757,9 @@ $post_array['post_title'] = $this->event_name; $post_array['post_content'] = $this->post_content; $post_array['post_excerpt'] = $this->post_excerpt; + if ( isset($this->event_slug) ) { + $post_array['post_name'] = $this->event_slug; + } //decide on post status if( empty($this->force_status) ){ if( count($this->errors) == 0 ){
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Allow event slug to be specified’ is closed to new replies.