Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //add_filter('name_save_pre', 'custom_event_slug');
- add_filter('wp_unique_post_slug', 'custom_event_slug', 100, 6);
- function custom_event_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug='' /* @since WP3.5 */) {
- global $post;
- if($post_status != "publish") return $slug;
- if(!is_object($post)) return $slug;
- $old_slug = $slug;
- if($post->post_type == "event" && class_exists('EM_Events') ){
- $slug = array();
- $custom =get_post_custom(); //get custom fields, holds em meta data like date, location id
- $locid = $custom['_location_id'][0]; //get the location ID for the event
- if($locid != 0) { //if there is a location
- $location_meta = EM_Locations::get($locid); //use EM_Locations class::get to get location meta
- $location_slug = $location_meta[0]->location_slug; //get the location_slug
- $slug[] = $location_slug;
- }
- $start_date = strtotime($custom['_event_start_date'][0]); //get the start date
- $slug[]= strftime("%Y-%m-%d"); //reformat it
- $slug []= sanitize_title($post->post_title); //the original post title
- //$locid = $_POST['location_id'];
- $slug = implode("-", $slug);
- }
- if(strlen($slug)< 3 )
- $slug == $old_slud;
- return $slug;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement