此方法对做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有修改过,记得做相应更改。
发现共鸣
Warning: curl_setopt() expects parameter 1 to be resource, null given in /www/wwwroot/blog.longshi.org/usr/themes/armx/functions.php on line 1531
如是说:辉煌一刻谁都有,别拿一刻当永久。