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有修改过,记得做相应更改。

分类: WordPress

2 条评论

落英缤纷 · 2020年11月22日 下午10:22

我想修改其中一些文章为指定时间,不会写SQL

UPDATE `wp_posts` SET `post_date` = replace(‘2020-11-20′,’2020-11-09’) WHERE `ID` between 129 AND 141;

我这个哪里错了呢

    博主 · 2020年11月29日 上午2:05

    Bulk edit publish date 插件支持对WordPress文章类型批量修改发布日期

发表评论

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