Slearn 升级到 Slearn Pro 主题
数据修改可通过 Better Search Replace 插件或者使用 SQL 语句,插件更为简便,SQL 语句修改更为高效。
修改前请一定备份好数据库。
1、使用插件替换,输入要替换和替换的内容,选择对应的数据库表,「作为模拟运行」不要勾选,勾选了不会替换数据。
2、使用 SQL 替换,将 SQL 语句添加到输入框,一行一条语句,可多行,确定后点击「执行」即可完成。也可点击「模拟查询」,可查看是否有数据有被替换。
一、自定义字段
1、面包屑内容
分别搜索:bgimg、describe、opacity,替换为:crumbs_bg、crumbs_describe、crumbs_opacity,选择『wp_postmeta』表
// SQL语句: update wp_postmeta set meta_key = replace( meta_key, 'bgimg', 'crumbs_bg' )
2、课程价格
分别搜索:_lp_price、_lp_sale_price、lp_course_options,替换为:regular_price、sale_price、preview_type,选择『wp_postmeta』表
// SQL语句: update wp_postmeta set meta_key = replace( meta_key, '_lp_price', 'regular_price' )
2、产品价格
分别搜索:_regular_price、_sale_price,替换为:regular_price、sale_price,选择『wp_postmeta』表
// SQL语句: update wp_postmeta set meta_key = replace( meta_key, '_regular_price', 'regular_price' )
二、文章类型
1、课程
搜索:lp_course,替换为:course,选择『wp_posts』表
// SQL语句: update wp_posts set post_type = replace( post_type, 'lp_course', 'course' )
搜索:lp_lesson,替换为:lesson,选择『wp_posts』表
// SQL语句: update wp_posts set post_type = replace( post_type, 'lp_lesson', 'lesson' )
搜索:course_category,替换为:course-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'course_category', 'course-cat' )
搜索:course_tag,替换为:course-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'course_tag', 'course-tag' )
课程目录循环到新的字段,将如下代码添加到主题根目录下的 functions.php 文件的最下方,保存后刷新下前台后,即可删除这段代码
// 将 LearnPress 插件中的课程列表循环到 Slearn Pro 主题课程选项中 // 将 LearnPress 插件中的课程列表循环到 Slearn Pro 主题课程选项中 $query = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'course' )); foreach ($query as $key => $post) { global $wpdb; $table_sections = $wpdb->prefix . 'learnpress_sections'; // 表前缀 $table_items = $wpdb->prefix . 'learnpress_section_items'; // 表前缀 $sections = $wpdb->get_results("SELECT * FROM $table_sections WHERE `section_course_id` = $post->ID", ARRAY_A); // 获取章节 $new_data = []; // 通过章节 ID 获取课时 ID foreach ($sections as $k1 => $v1) { $section_id = $v1['section_id']; // 章节 ID $section_name = $v1['section_name']; // 章节名称 $section_description = $v1['section_description']; // 章节描述 $items = $wpdb->get_results("SELECT * FROM $table_items WHERE `section_id` = $section_id", ARRAY_A); // 获取课时与测验 $new_data[$k1]['title'] = $section_name; $new_data[$k1]['describe'] = $section_description; foreach ($items as $k2 => $v2) { $item_id = $v2['item_id']; // 项目 ID $item_type = $v2['item_type']; // 项目类型 $new_data[$k1]['type'] = $item_type; // 注意:如果使用插件或者 sql语句替换了 lp_lesson,判断条件为:$item_type === 'lesson',否则:$item_type === 'lp_lesson' if ($item_type === 'lesson') { $new_data[$k1]['lessons'][] = $item_id; } } } update_post_meta($post->ID, 'course_section', $new_data); }
2、产品
搜索:product_cat,替换为:product-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'product_cat', 'product-cat' )
搜索:product_tag,替换为:product-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'product_tag', 'product-tag' )
3、作品
搜索:pcat,替换为:portfolio-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'pcat', 'portfolio-cat' )
搜索:ptag,替换为:portfolio-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'portfolio_tag', 'portfolio-tag' )
4、团队
搜索:tcat,替换为:team-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'tcat', 'team-cat' )
搜索:ttag,替换为:team-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'ttag', 'team-tag' )
搜索:team_social,替换为:social_buttons,选择『wp_postmeta』表
// SQL语句: update wp_postmeta set meta_key = replace( meta_key, 'team_social', 'social_buttons' )
5、活动
搜索:tp_event,替换为:event,选择『wp_posts』表
// SQL语句: update wp_posts set post_type = replace( post_type, 'tp_event', 'event' )
搜索:tp_event_category,替换为:event-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'tp_event_category', 'event-cat' )
搜索:tp_event_tag,替换为:event-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'tp_event_tag', 'event-tag' )
6、服务
搜索:scat,替换为:service-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'scat', 'service-cat' )
搜索:ttag,替换为:service-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'ttag', 'service-tag' )
循环特长到主题字段中,将如下代码添加到主题根目录下的 functions.php 文件的最下方,保存后刷新下前台后,即可删除这段代码
$query = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'team' )); foreach ($query as $key => $post) { $team_speciality_bg = get_post_meta($post->ID, 'team_speciality_bg', true); $team_speciality_title = get_post_meta($post->ID, 'team_speciality_title', true); $team_speciality_sub_title = get_post_meta($post->ID, 'team_speciality_sub_title', true); $team_speciality = get_post_meta($post->ID, 'team_speciality', true); // 循环特长 if($team_speciality) { foreach ($team_speciality as $key => $value) { $team_speciality[$key]['title'] = $value['title']; $team_speciality[$key]['percent'] = $value['desc']; } $new_data = [ 'title' => $team_speciality_title, 'subtitle' => $team_speciality_sub_title, 'lists' => $team_speciality, 'title_layout' => 'justify', 'list_width' => 'wrapper', 'row_count' => '2', ]; // 如果有背景图片 if($team_speciality_bg){ $new_data['bg_img'] = $team_speciality_bg; $new_data['bg_color'] = 'rgba(0,0,0,0.8)'; $new_data['bg_blur'] = 10; } update_post_meta($post->ID, 'skills', $new_data); } }
7、服务
搜索:vcat,替换为:video-cat,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'vcat', 'video-cat' )
搜索:vtag,替换为:video-tag,选择『wp_term_taxonomy』表
// SQL语句: update wp_term_taxonomy set taxonomy = replace( taxonomy, 'vtag', 'video-tag' )
循环视频选项到主题字段中,将如下代码添加到主题根目录下的 functions.php 文件的最下方,保存后刷新下前台后,即可删除这段代码
$query = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'video' )); foreach ($query as $key => $post) { $videos = get_post_meta($post->ID, 'videos', true); $captions = get_post_meta($post->ID, 'captions', true); $cover = get_post_meta($post->ID, 'cover', true); $duration = get_post_meta($post->ID, 'duration', true); $duration = $duration ? explode(':', $duration) : ''; // 如果有设置视频 if ($videos) { foreach ($videos as $key => $value) { $videos[$key]['size'] = $value['size']; $videos[$key]['src'] = $value['video']; } // 有字幕 if ($captions) { foreach ($captions as $key => $value) { $captions[$key]['language'] = $value['language']; $captions[$key]['badge'] = $value['badge']; $captions[$key]['src'] = $value['caption']; } } // 有时长 if ($duration) { $video_duration = [ 'right' => $duration[0], 'bottom' => $duration[1], ]; update_post_meta($post->ID, 'video_duration', $video_duration); } $new_data = [ 'videos' => $videos, 'captions' => $captions, 'cover' => $cover, 'capability' => 'free', ]; update_post_meta($post->ID, 'video_type', 'html5'); update_post_meta($post->ID, 'video_html5', $new_data); } }