mbis

GeomyWP fields

May 19th, 2021 (edited)
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Random string in permastructure
  3.  * Use %state% and %city% in "Permastructure" settings
  4.  */
  5. function pm_extra_permastructure_tags($default_uri, $native_slug, $post, $slug, $native_uri) {
  6.     // Do not affect native URIs
  7.     // Limit to 'product' post type only
  8.     if($native_uri == true || empty($post->post_type) || $post->post_type !== 'product') { return $default_uri; }
  9.  
  10.     // Store post ID in a separate variable
  11.     $post_id = $post->ID;
  12.  
  13.     // Get post location data
  14.     $post_location = gmw_get_post_location_data($post_id);
  15.    
  16.     if(strpos($default_uri, '%state%') !== false) {
  17.         // Use GeomyWP API to get the 'state' field
  18.         // ...
  19.  
  20.         $state = '';
  21.        
  22.         $default_uri = str_replace('%state%', $state, $default_uri);
  23.     }
  24.  
  25.     if(strpos($default_uri, '%city%') !== false) {
  26.         // Use GeomyWP API to get the 'city' field
  27.         // ...
  28.  
  29.         $city = '';
  30.        
  31.         $default_uri = str_replace('%city%', $city, $default_uri);
  32.     }
  33.    
  34.     return $default_uri;
  35. }
  36. add_filter('permalink_manager_filter_default_post_uri', 'pm_extra_permastructure_tags', 3, 5);
Add Comment
Please, Sign In to add comment