Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1.  
  2. function recipes_post_link( $post_link, $id = 0 ){
  3.     $post = get_post( $id );
  4.     if ( is_object( $post ) ){
  5.         //$terms = wp_get_object_terms( $post->ID, 'recipe-category' );
  6.         $terms = get_the_terms( $post->ID, 'recipe-category' );
  7.         //echo '<pre>' . var_dump($terms) . '</pre>';
  8.         foreach($terms as $term) {
  9.             if( $term->slug == 'ristorante' || $term->slug == 'utenti'){
  10.                 //var_dump($post_link);
  11.                 //var_dump($term->slug);
  12.                 return str_replace( site_url()."/ricetta" , site_url()."/ricetta/".$term->slug , $post_link );
  13.             }
  14.         }
  15.     }
  16.     return $post_link;
  17. }
  18. add_filter( 'post_type_link', 'recipes_post_link', 1, 3 );
  19.  
  20. function custom_rewrite_basic() {
  21.   add_rewrite_rule('^ricetta/(.+)/(.+)', 'index.php?recipe=$matches[2]', 'top');
  22. }
  23. add_action('init', 'custom_rewrite_basic');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement