I know it should work fine, don't know if this is a recent bug or something. So, to confirm it, I installed a fresh wordpress using default theme. I made a small plugin like bellow:
<?php
/*
Plugin Name: Test
Plugin URI: http://www.something.com
Description: To test
Version: 1.0
Author: Yet another dev
Author URI: http://me.com
*/
add_filter('post_type_link', 'wpse33551_post_type_link', 1, 2);
function wpse33551_post_type_link( $link, $post = 0 ){
return home_url( 'temp-tests/' . $post->ID );
}
add_action('init', 'sfsafsdsf_test');
function sfsafsdsf_test(){
wp_die(get_permalink(1));
}
But for some reason it's still showing:
http://example.com/2016/06/22/hello-world/
Let me know if I'm wrong at something.
Edit
My concern is that above code should output this (or let me know if I'm wrong at something):
http://example.com/temp-tests/1
When I said "output", I mean the permalink for postID #1 should be like that.
Edit 2
No, this isn't a custom post type. I'm using default "post" for this.
get_permalink
is not callingget_post_permalink
for built-in post types. Therefore the filtering never takes place the way you've set it up. Try usingget_post_permalink
instead, which is the function thatpost_type_link
filters as stated in the codex.