Last active
April 29, 2022 18:16
-
-
Save sethryder/22c4ed1b8a7b3b31090ace2cfd39fb09 to your computer and use it in GitHub Desktop.
update redirects in yoast when changing from date based permalinks to just post name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$option_value_export_plain = file_get_contents('export_plain.txt'); | |
$option_value_base = file_get_contents('base.txt'); | |
$export_plain = unserialize($option_value_export_plain); | |
$base = unserialize($option_value_base); | |
$new_export_plain = []; | |
foreach ($export_plain as $k => $redirect) { | |
$new_url = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $redirect['url']); | |
$new_key = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $k); | |
$new_export_plain[$new_key] = []; | |
$new_export_plain[$new_key]['url'] = $new_url; | |
$new_export_plain[$new_key]['type'] = $redirect['type']; | |
} | |
foreach ($base as $k => $redirect) { | |
$new_origin = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $redirect['origin']); | |
$new_url = preg_replace("/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\//", "", $redirect['url']); | |
$new_base[] = array( | |
'origin' => $new_origin, | |
'url' => $new_url, | |
'type' => $redirect['type'], | |
'format' => $redirect['format'] | |
); | |
} | |
file_put_contents('fixed_export_plain.txt', serialize($new_export_plain)); | |
file_put_contents('fixed_base.txt', serialize($new_base)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment