admin管理员组文章数量:1418017
I want to migrate my development wordpress site to the production domain. In order to success the migration I found and replace all previous url occurences (http://localhost) to the new ().
The problem is that old urls cannot be replaced directly in the field option_value
of theme_mods_{your theme name}
in the table wp_options
because data in there are serialized.
How can I replace old urls by the new without breaking theme settings ?
I want to migrate my development wordpress site to the production domain. In order to success the migration I found and replace all previous url occurences (http://localhost) to the new (https://mywebsite).
The problem is that old urls cannot be replaced directly in the field option_value
of theme_mods_{your theme name}
in the table wp_options
because data in there are serialized.
How can I replace old urls by the new without breaking theme settings ?
Share Improve this question asked Jul 30, 2019 at 15:24 Louis D.Louis D. 1012 bronze badges 1- You shouldn't store URLs, store attachment post IDs instead then use the API functions to get the URL back. Then you won't need to change them when you migrate the site. Have you looked at the WP CLI search replace command? – Tom J Nowell ♦ Commented Jul 30, 2019 at 15:38
2 Answers
Reset to default 1Use the official CLI tool:
wp search-replace 'http://localhost' 'https://yoursitecom'
It will automatically deserialize any post meta, options, theme mods, etc and adjust them to match the new URL.
Fundamentally though, it's bad practice to store URLs to images posts and assets in the database. Store the post ID instead, and this problem goes away
It's possible to search and replace old urls to new ones by using maybe_unserialize(get_theme_mods())
and get_theme_mod()
WP functions and following these steps:
- Create a php file in the root folder of your WP installation (same path as
wp-load.php
). - Insert the following code :
require_once("wp-load.php");
$r = maybe_unserialize(get_theme_mods());
foreach ($r as $k => $v){
if(!empty($k)){
$ListOptions[] = $k;
}
}
foreach($ListOptions as $option){
$str = get_theme_mod($option);
$str = str_replace('http://localhost', 'https://mywebsite', $str);
$str = str_replace('http:\\/\\/localhost', 'https:\\/\\/mediadroit.fr', $str);
set_theme_mod($option, $str);
var_dump('|'.$option.': '.get_theme_mod($option).' ===> '.$str);
echo "\n";
}
- Execute the script
本文标签: Issue with theme mod options during domain migration
版权声明:本文标题:Issue with theme mod options during domain migration 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745283528a2651567.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论