记录:数据转换成功加入WordPress大家族

老杨今儿正式加入WordPress大家族。

先记录一下:

update wp_postmeta set meta_value = meta_value+200 where post_id=100 and meta_key='views';
insert into wp_postmeta (post_id, meta_key, meta_value) values ('100', 'views', '200');

评论字段替换

评论部分由于之前转换过程中一个不注意,留下了很多郁闷的链接,内容类似如下:

新年快乐!<pre><div><div><a rel="nofollow" href="http://localhost:507/function/c_urlredirect.asp?url=h4t7t6p4%3A3%2F6%2F2w1w4w6%2E4n6u5o0d2o8u6%2E9c6o5m4" target="_blank" rel="nofollow">nuodou</a> 于 2011-1-1 9:51:18 回复</div>同乐!</div></pre>

其中的url是随机字符,想要批量替换其中的url还是比较头疼的,后经一位群友的帮助,直接在phpmyadmin里使用以下SQL语句进行了替换,结果很棒

update wp_comments set comment_content=CONCAT(SUBSTRING_INDEX(comment_content,'localhost:507',1),'yangjunwei.com" target="_blank"',SUBSTRING_INDEX(comment_content,' target="_blank" rel="nofollow"',-1)) WHERE `comment_content` LIKE '%localhost:50%'

 顺便说明一下两个函数的使用说明:

SUBSTRING_INDEX 函数的功能是拆分字符串

SUBSTRING_INDEX(comment_content,'localhost:507',1)  获取comment_content字段中 localhost:507 之前的字符串

SUBSTRING_INDEX(comment_content,' target="_blank" rel="nofollow"',-1) 获取comment_content字段中 target="_blank" rel="nofollow" 之后的字符串

CONCAT 函数的功能是合并字符串,两函数联合使用,就能完成将上述原始评论内容转换为以下内容:

新年快乐!<pre><div><div><a rel="nofollow" href="http://yangjunwei.com" target="_blank" rel="nofollow">nuodou</a> 于 2011-1-1 9:51:18 回复</div>同乐!</div></pre>

本文持续更新中......