Advertisement
mbis

Update the permalink after the term is assigned

May 11th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. function pm_regenerate_custom_permalinks($post_id) {
  2.     global $permalink_manager_uris;
  3.  
  4.     if(!empty($permalink_manager_uris)) {
  5.         $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id);
  6.  
  7.         if($default_uri) {
  8.             if(!empty($_POST['custom_uri'])) {
  9.                 $_POST['custom_uri'] = $default_uri;;
  10.             }
  11.  
  12.             $permalink_manager_uris[$post_id] = $default_uri;
  13.             update_option('permalink-manager-uris', $permalink_manager_uris);
  14.         }
  15.     }
  16. }
  17.  
  18. function pm_update_post_terms($object_id, $terms, $tt_ids, $taxonomy) {
  19.     // Trigger only for selected taxonomies
  20.     if(!in_array($taxonomy, array('product_cat'))) { return; }
  21.  
  22.     // Trigger only for selected post types
  23.     $post = get_post($object_id);
  24.     if(!empty($post->post_type) && !in_array($post->post_type, array('product'))) { return; }
  25.  
  26.     pm_regenerate_custom_permalinks($object_id);
  27. }
  28. add_action('set_object_terms', 'pm_update_post_terms', 9, 4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement