function mycustomname_links($post_link, $post = 0) {
    if($post->post_type === 'ctp_mycustomname') {
        return home_url('mycustomname/' . $post->ID . '/');
    }
    else{
        return $post_link;
    }
}
add_filter('post_type_link', 'mycustomname_links', 1, 3);
function mycustomname_rewrites_init(){
    add_rewrite_rule('mycustomname/([0-9]+)?$', 'index.php?post_type=ctp_mycustomname&p=$matches[1]', 'top');
}
add_action('init', 'mycustomname_rewrites_init');

source: https://wordpress.stackexchange.com/questions/195458/custom-post-type-permalink-only-use-post-id-and-remove-postname

Leave a Comment