Instantly share code, notes, and snippets.

Embed
What would you like to do?
update redirects in yoast when changing from date based permalinks to just post name
<?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