Viewing 3 replies - 1 through 3 (of 3 total)
  • try this

    add_action('save_post', 'change_slug', 10, 2 );
    function change_slug( $id, $post = false ){
     global $wpdb;
     if( 'product' == $post->post_type ){
       $custom_slug = get_post_meta( $id, 'serial', true );
       $custom_slug .= "-". get_post_meta( $id, 'model_name', true );
    
       $wpdb->update( $wpdb->posts, array( 'post_name' => $custom_slug ), array( 'ID' => $post->ID ));
      return $id;
     }
    
     return $id;
    }

    Just don’t know if slashes would work, so use dashes instead. But, you can try slashes.

    Thread Starter lucaskeiser

    (@lucaskeiser)

    That worked smashingly! How could I also make that slug the title for the page?

    How could I also make that slug the title for the page?

    $wpdb->update( $wpdb->posts, array( 'post_name' => $custom_slug, 'post_title' => $custom_slug ), array( 'ID' => $post->ID ));
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Type Rewrite Confussion’ is closed to new replies.