Slhao 升级到Slhao Pro主题
数据修改可通过 Better Search Replace 插件或者使用 SQL 语句,插件更为简便,SQL 语句修改更为高效。
修改前请一定备份好数据库。
1、使用插件替换,输入要替换和替换的内容,选择对应的数据库表,「作为模拟运行」不要勾选,勾选了不会替换数据。
2、使用 SQL 替换,将 SQL 语句添加到输入框,一行一条语句,可多行,确定后点击「执行」即可完成。也可点击「模拟查询」,可查看是否有数据有被替换。
一、自定义字段
1、推门推荐
搜索:hot
,替换为:switch_hot
,数据表:wp_postmeta
// SQL语句:
update wp_postmeta set meta_key = replace( meta_key, 'bgimg', 'crumbs_bg' )
2、想读|在读|已读字段
分别搜索:wishs、wish_modified、dos、do_modified、collects、collect_modified
,替换为:wantRead_count、wantRead_modified、reading_count、reading_modified、read_count、read_modified
,数据表:wp_postmeta
// SQL语句:
update wp_postmeta set meta_key = replace(meta_key, 'wishs', 'wantRead_count')
update wp_postmeta set meta_key = replace(meta_key, 'wish_modified', 'wantRead_modified')
update wp_postmeta set meta_key = replace(meta_key, 'dos', 'reading_count')
update wp_postmeta set meta_key = replace(meta_key, 'do_modified', 'reading_modified')
update wp_postmeta set meta_key = replace(meta_key, 'collects', 'read_count')
update wp_postmeta set meta_key = replace(meta_key, 'collect_modified', 'read_modified')
二、工具下载参数
// 添加到主题根目录下的 functions.php 最后面,访问下前台即可
$tools = get_posts(array(
'post_type' => 'tool',
'posts_per_page' => -1,
));
foreach ($tools as $tool) {
$post_id = $tool->ID;
$download_list = get_post_meta($post_id, 'download_list', true);
// 如果 download_list 字段有值
if (!empty($download_list)) {
$lists = [];
foreach ($download_list as $key => $value) {
$value['type'] = 'link'; // 设置默认类型为链接
$value['fetch_code'] = $value['password']; // 将密码添加到提取码中
$lists[] = $value;
}
// 更新 downloads['urls']
update_post_meta($post_id, 'downloads', array('urls' => $lists));
// 设置 switch_download 字段为 '1'
update_post_meta($post_id, 'switch_download', '1');
}
}