posts with url-encoded post_name dropped
-
Hi there – thank you for this amazing plugin!
I just noticed that some of my posts were missing from the static export. Turns out it was posts that had url-encoded values as their
post_name, for example this: “bedo%cc%88” (wich is, after urldecode, equivalent to “bedö”. Something in simply static is preventing these posts from being exportet.As a hotfix, I’ve created this little WP-CLI script that “prepares” all my
post_namevalues – but of course, these will lead to 404s (I’m archiving a site that was existing in it’s dynamic form for a long time). Not ideal but oh well. Here’s the script:/**
* Sanitize permalinks so that simply-static doesn't miss them in it's exports
* Usage: wp sanitize-permalinks
*/
if (defined('WP_CLI') && WP_CLI) {
WP_CLI::add_command('sanitize-permalinks', function() {
$post_types = array_values([
'page',
...get_post_types(['public' => true, '_builtin' => false])
]);
$posts = get_posts([
'post_type' => $post_types,
'post_status' => 'any',
'posts_per_page' => -1,
]);
foreach ($posts as $post) {
$original = $post->post_name;
$sanitized = sanitize_title(urldecode($original));
if ($original === $sanitized) continue;
wp_update_post([
'ID' => $post->ID,
'post_name' => $sanitized
]);
WP_CLI::success("Sanitized post_name for '$post->post_title'. Before: $original, After: $sanitized");
}
});
}
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.