‘post_type_link’ filter not working

It is not a bug. As @LuisSanz pointed out, post_type_link isn’t used for the built-in post post type. It is used for custom post types only.

Skim through get_permalink() function, you will find out that WordPress doesn’t use post_type_link filter but uses post_link filter. It means that you’re using wrong filter.

Then, change post_type_link to post_link should fix the problem:

add_filter('post_link', 'wpse230567_filter_post_link', 1, 2);

function wpse230567_filter_post_link($link, $post = 0)
{
    return home_url('temp-tests/' . $post->ID);
}

Leave a Comment