您的位置 首页 WordPress

WordPress文章日期批量随机修改

此方法对做WordPress批量采集的、发文章时间不符合实际的站点,例如文章状态为“草稿”很久了,原计划发布时间是上个月,结果这个月才完稿发布,类似情况很有帮助,省去一个个修改的烦恼。这是在网上找到的两段SQL语句,存在瑕疵:

//时间格式不对
UPDATE `wp_posts` SET `post_date` = DATE_ADD('2010-1-01', INTERVAL ROUND(RAND() * 3890+ 1) DAY) WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_modified` = `post_date` WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_date_gmt` = `post_date` WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_modified_gmt` = `post_modified` WHERE `ID` between 1 AND 100000;
update `wp_posts` set `post_status` = 'publish' WHERE `ID` between 1 AND 100000;

//时间格式不对
UPDATE `wp_posts` SET `post_date` = DATE_ADD('2018-1-10', INTERVAL ROUND(RAND() * 220 + 1) DAY)  WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_modified` = `post_date` WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_date_gmt` = `post_date` WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_modified_gmt` = `post_modified` WHERE `ID` between 1 AND 1215;
update `wp_posts` set `post_status` = 'publish' WHERE `ID` between 1 AND 1215;


起始时间 “2020-01-01”
随机日期范围 “180 天”
文章ID起始范围 “1 - 2000”
任意修改,然后依次执行以下SQL语句,每个分号是一句,一句一句执行,可以在指定的文章ID范围内,随机生成文章的发布日期,替换原来的日期。

//完美
UPDATE `wp_posts` SET `post_date` = DATE_ADD('2020-01-01', INTERVAL ROUND(RAND() * 180 + 1) DAY)  WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_modified` = `post_date` WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_date_gmt` = `post_date` WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_modified_gmt` = `post_modified` WHERE `ID` between 1 AND 2000;
update `wp_posts` set `post_status` = 'publish' WHERE `ID` between 1 AND 2000;


字段含义:
post_date(文章发布日期)
post_date_gmt(文章发布日期,格林威治时间)
post_modified(文章修改时间)
post_modified_gmt(文章修改时间,格林威治时间)
post_status(文章状态)
如果安装WordPress的时候数据库表前缀wp有修改过,记得做相应更改。

未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源:https://cn.fankuiba.com/455.html

作者: 博主

发表评论

电子邮件地址不会被公开。 必填项已用*标注

返回顶部