Advertisement
Guest User

custom events manager slug

a guest
Jul 6th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. //add_filter('name_save_pre', 'custom_event_slug');
  2. add_filter('wp_unique_post_slug', 'custom_event_slug', 100, 6);
  3.  
  4. function custom_event_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug='' /* @since WP3.5 */) {
  5.     global $post;
  6.     if($post_status != "publish") return $slug;
  7.     if(!is_object($post)) return $slug;
  8.     $old_slug = $slug;
  9.     if($post->post_type == "event" && class_exists('EM_Events') ){
  10.         $slug = array();
  11.         $custom =get_post_custom();  //get custom fields, holds em meta data like date, location id
  12.         $locid = $custom['_location_id'][0];                        //get the location ID for the event
  13.         if($locid != 0) {                                           //if there is a location
  14.             $location_meta = EM_Locations::get($locid);             //use EM_Locations class::get to get location meta
  15.             $location_slug = $location_meta[0]->location_slug;      //get the location_slug
  16.             $slug[] = $location_slug;
  17.                
  18.         }
  19.         $start_date = strtotime($custom['_event_start_date'][0]);   //get the start date
  20.         $slug[]= strftime("%Y-%m-%d");                          //reformat it
  21.        
  22.         $slug []= sanitize_title($post->post_title);                                //the original post title
  23.         //$locid = $_POST['location_id'];
  24.         $slug = implode("-", $slug);
  25.     }
  26.     if(strlen($slug)< 3 )
  27.         $slug == $old_slud;
  28.     return $slug;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement