I’m having trouble getting the permalink sample on my custom post type edit page to work

I have set up two custom post types (show & podcast) and I have parented podcast to show by following this awesome tutorial: https://1fix.io/blog/2016/02/05/parent-from-another-cpt/

The rewrite rules are working perfectly, but my permalink still shows %show% in the url when I’m editing my podcast like so:

http://example.com/podcast/%show%/sample-podcast-title

Here is my rewrite code:

add_rewrite_tag(‘%podcast%’, ‘([^/]+)’, ‘podcast=’);
add_permastruct(‘podcast’, ‘podcast/%show%/%podcast%’, false);
add_rewrite_rule(‘^podcast/([^/]+)/([^/]+)/?’,’index.php?podcast=$matches[2]’,’top’);

With this code, I can see the page with /podcast/whatever-I-want/podcast-name and it works beautifully.

Here is my post_link_type filter function:

function mySite_post_link_type($permalink, $post){
if($post->post_type == ‘podcast’) {
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace( ‘%show%’, $parent_post->post_name, $permalink );
}
return $permalink;
}
add_filter( ‘post_link_type’, ‘mySite_post_link_type’, 10, 2 );

This should be updating my permalink correctly but it’s not. I’ve tried flushing my cache, saving permalinks, etc., but it still appears on my permalink.

Do I need to adjust the priority? Am I missing something?

Thanks for any help.

Read more here:: I’m having trouble getting the permalink sample on my custom post type edit page to work

Leave a Reply

Your email address will not be published. Required fields are marked *