I’m working through a migration from Drupal to a WP multisite network, I’ve got a post meta field that contains the URL of the old post (mostly to maintain social counts and such) that I’m using for the permalink structure. I’m doing this with the following:
add_filter('post_link', 'migration_permalinks', 10, 3 );
function migration_permalinks( $permalink, $post, $leavename ) {
if( ($post->post_type == 'post' ) && ( $the_link = get_post_meta( $post->ID, '_the_old_site_permalink', true) ) ) {
$url = parse_url( $the_link );
$permalink = site_url() . $url['path'];
}
return $permalink;
}
The issue I run into is that if the post title contains an apostrophe, ’
(not a straight single quote '
), the post URL does not work. Encoded, that converts to %E2%80%99
. In the browser address bar, if I change the apostrophe to a straight single quote, the URL works and the post displays. The existing Drupal site contains the apostrophe (%E2%80%99
) without issue.
Maintaining the URL as is is pretty important because I don’t want any existing links to the page to 404 when the migration occurs. Why is the link not working when it contains an apostrophe?