できることはできたんですが、これを行うと他の固定ページやプラグインを利用していた場合にリンク切れになったりしたため実際に使うことはやめています……。
ex. roomというカスタム投稿名にしていた場合。
通常:http://URL/room/投稿名
変更後:http://URL/投稿ID
//カスタム投稿のURLからスラッグを抜く
add_action('init', 'myposttype_rewrite');
function myposttype_rewrite() {
global $wp_rewrite;
$queryarg = 'post_type=room&p=';
$wp_rewrite->add_rewrite_tag('%room_id%', '([^/]+)',$queryarg);
$wp_rewrite->add_permastruct('room', '/%room_id%', false);
}
add_filter('post_type_link', 'myposttype_permalink', 1, 3);
function myposttype_permalink($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ) )
return $post;
$newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
$newlink = str_replace('%'.$post->post_type.'_id%', $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}


