Custom Post Type Rewrite Structure Being Added To Sitemap
-
I know this is a long shot, but I have a custom post type ‘latest_resources’ which is being registered via a theme function. I am rewriting the permalink structure this way:
$args = [
....
"rewrite" => [ "slug" => "resources/%resource_type%", "with_front" => false ],
....
];
register_post_type( "latest_resource", $args );Then, I use a filter to replace the string %resource_type% with the custom taxonomy term:
function resources_change_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'latest_resource' ){
$terms = wp_get_object_terms( $post->ID, 'resource_type' );
if( $terms ){
return str_replace( '%resource_type%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'resources_change_permalinks', 1, 2 );Works great. And in the Yoast Sitemap under latest_resource-sitemap.xml all of the permalinks appear exactly how I want them. Everything looks wonderful…
EXCEPT the very first entry in the latest_resource-sitemap.xml sitemap is:
https://www.myURL.com/resources/%resource_type%/
I am unsure how to troubleshoot. Is there a way I can filter the sitemap to ensure this string is not included? Should I be rewriting the permalink structure another way?
Any insight or advice is greatly appreciated. Thanks!
- You must be logged in to reply to this topic.