Advertisement
Guest User

Untitled

a guest
Jan 4th, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. function repairman_permalink( $post_link, $post ) {
  2.     if ( is_object( $post ) && $post->post_type == 'repairman' ) {
  3.         $terms = wp_get_object_terms( $post->ID, 'city' );
  4.         if( $terms ) {
  5.             $term_slug = urldecode( $terms[0]->slug );
  6.             return str_replace( '%city%', $term_slug, $post_link );
  7.         }
  8.     }
  9.     return $post_link;
  10. }
  11. add_filter( 'post_type_link', 'repairman_permalink', 9, 2 );
  12.  
  13.  
  14.  
  15.  
  16. function repairman_permalink_structure( $post_link, $post ) {
  17.     if ( is_object( $post ) && $post->post_type == 'repairman' ) {
  18.         $terms = wp_get_object_terms( $post->ID, 'city' );
  19.         if( is_array( $terms ) && ! empty( $terms ) ) {
  20.             $term_slug = urldecode( $terms[0]->slug );
  21.             return home_url( 'майстори/' . $term_slug . '/' . $post->post_name . '/' );
  22.         }
  23.     }
  24.     return $post_link;
  25. }
  26. add_filter( 'post_type_link', 'repairman_permalink_structure', 10, 2 );
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement