Home>Article>CMS Tutorial> [Organize and share] Detailed explanation of how to batch modify article information in WordPress

[Organize and share] Detailed explanation of how to batch modify article information in WordPress

青灯夜游
青灯夜游 forward
2023-03-10 20:10:25 2875browse

How to batch modify article information in WordPress? The following article will introduce to you how to batch modify the article content, abstract, author, all comments, sensitive words and other information in WordPress. I hope it will be helpful to you!

[Organize and share] Detailed explanation of how to batch modify article information in WordPress

Have you ever encountered the following situations:

  • When a blog changes its domain name, the content of the blog article must also be changed
  • The image address used has been changed
  • I have written a lot of articles, and I want to switch authors
  • I want to delete all the messages of a certain hateful commenter
  • Want to change the website URL of all comments by a commenter
  • Want to disable pingback of all articles
  • Want to disable the comment function of all articles

All of these , all involve one keyword:Batch modification. If you manually modify the content of articles one by one in the WordPress backend, I believe it will drive you crazy. For some blogs with thousands of articles, it is almost impossible to complete the task. This article will teach you how to use SQL statements to operate your database and achieve batch modification of data.

If you have never learned database-related knowledge, you definitely don’t know what SQL is, but the content covered in this article does not require you to understand database knowledge, nor does it require you to be proficient in writing SQL statements. You are completely You can directly use the SQL mentioned in this article. Below we will introduce the functions of each SQL statement in sections. All statements use the defaultwp_table prefix. If yours is not, please change it yourself.

Before we begin, let’s first introduce how to execute SQL statements and perform batch operations. Nowadays, most spaces use phpmyadmin to manage databases. Here we will use phpmyadmin as an example to introduce how to execute SQL statements:

  • Enter your phpmyadmin management page, and then enter your blog corresponding There is a

    SQL
  • option in the menu bar of the database
  • . Click in

  • and an input box for the SQL statement will appear. Now You can enter the SQL statement in it

  • After inputting, clickExecute, the SQL statement you just entered will be executed

  • The SQL statement has been executed, and your articles have been modified in batches. Now go and see if all your articles have been changed.

  • Finally, a reminder: the SQL introduced below The statements have been tested on my blog, but despite this, you must back up your database before operating the database; it is a good habit to back up your database regularly

SQL command execution Window:

[Organize and share] Detailed explanation of how to batch modify article information in WordPress

1. Modify article content in batches:

If you want to replace what you have written before For certain content in all articles, such as changing the name of the blog, changing the URL of the blog, changing the link of the article image, etc., you can use the following SQL statement:

UPDATE wp_posts SET post_content = replace( post_content, '露兜博客', '露兜中文博客' );

This statement The function is to replace the wordsPandan Blogin all articles withPandan Chinese Blog. You can make some changes as needed. Because the article content is stored in the form of HTML code in the database, the above SQL statement can also replace the HTML code.

If you just want to change the link to the article illustration without affecting other links, you can use the following SQL statement. All src="oldurl.com is replaced with src="newurl.com

UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="oldurl.com', 'src="newurl.com');

If you upload it as an image attachment, you need to change the GUID of the image attachment

UPDATE wp_posts SET guid = REPLACE (guid, 'oldsiteurl.com', 'newsiteurl.com') WHERE post_type = 'attachment';

2. Modify the article summary in batches:

The article summary is the content entered in the "Summary" box when you edit the article in the WordPress background. If you want to change the article summary in batches, you can use the following statement:

UPDATE wp_posts SET post_excerpt = replace( post_excerpt, '露兜博客', '露兜中文博客' );

The function of this statement is to replace all the wordsPandan Blogin all article summaries withPandan Chinese Blog.

3. Batch modify the authors of articles:

Suppose your blog has two registered users, Zhang San and Li Si, and you want to modify all Zhang San’s articles Under the leadership of Li Si, what should we do now? You can execute the following statement:

UPDATE wp_posts SET post_author = 李四用户id WHERE post_author = 张三用户id;

How to get the user ID of Li Si and the user ID of Zhang San? You can execute the following SQL statement:

SELECT ID, user_nicename, display_name FROM wp_users;

The IDs, nicknames and publicly displayed names of all registered users on your blog will be listed. You can now find the corresponding user ID, as shown below, the ID of zhangsan is 2, and the ID of lisi is 5:

[Organize and share] Detailed explanation of how to batch modify article information in WordPress

Your SQL can be written like this:

UPDATE wp_posts SET post_author = 5 WHERE post_author = 2;

4、批量修改文章评论者的网站URL:

假设,你的博客有个非常忠实的读者,给你的博客文章留下很多有用的评论,同时他的评论都填写了留言者的网站URL,但是有一天他的博客域名换了,并请求你更新他留言中的网站URL,那你怎么办?手动一个一个帮他改,这不太现实。你可以使用以下SQL语句:

UPDATE wp_comments SET comment_author_url = REPLACE( comment_author_url, 'oldurl.com', 'newurl.com' )

以上语句,将留言者所有旧的网站链接oldurl.com,更改为新的网址newurl.com

5、禁用所有文章的pingback功能:

开启pingback功能,可以在别人引用你的文章链接的情况下,给你发送通知,但是该功能似乎对我们的文章没多大帮助,那为何不把pingback给禁止了呢?在WordPress后台 - 设置 - 讨论,取消勾选"接收来自外部博客的引用通告(pingbacks 和 trackbacks)",这样以后的文章都不开启pingback,但是该选项不会对之前的已发布的文章起作用,还是要用到SQL:

UPDATE wp_posts SET ping_status = 'closed';

6、删除所有文章的修订版:

在通常情况下,文章的修订版对大多数人来说没多大意义,而且修订版的数量会随着你修改文章的次数不断增长,这会增加数据库的查询速度,这并不是什么好事。互联网上有很多教你如何禁止修订版的文章,还有很多插件可以删除文章修订版,你可以自己搜索看看。这里教你如何使用SQL语句,删除所有已产生的文章修订版数据:

DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';

7、删除某个评论者的所有评论:

如果你的博客想要封杀某人,并删除其在你博客的所有留言,可以使用以下SQL语句。

(1)根据留言者的博客URL进行删除,以下SQL语句将删除所有URL为www.example.com的评论

DELETE from wp_comments WHERE comment_author_url LIKE '%www.example.com%';

(2)根据留言者的昵称进行删除,以下语句将删除所有昵称为example的评论

DELETE from wp_comments WHERE comment_author = 'example';

(2)根据留言者的Email进行删除,以下语句将删除所有Email为example@example.com的评论

DELETE from wp_comments WHERE comment_author_email = 'example@example.com';

8、替换所有评论中的敏感词汇:

国内的互联网监控力度表现出了不断加强的趋势,如果你的博客评论中出现了大量的敏感词汇,很可能离被墙也不远了。最好的做法是,替换相关的敏感词汇,以保证你的博客安全,以下SQL语句将所有评论中的fuck,替换成 **,替换内容根据你的需要来。

UPDATE wp_comments SET comment_content = replace( comment_content, 'fuck', '**' );

9、关闭文章评论功能

有时候你的博客可能会因为某种原因,需要关闭文章的评论。在WordPress后台 - 设置 - 讨论,那里取消勾选"允许人们发表新文章的评论",以后发表的文章默认是关闭评论的。但是之前已经发表的文章,若想关闭评论需要你一篇一篇地去修改评论设置,这是一件比较痛苦的事情。以下SQL语句可以帮助你轻松地批量关闭文章评论:

(1) 关闭所有旧文章的评论:
通常情况下,一篇旧文章就很少会有人发表评论了,一般访问旧文章的访客大都来自搜索引擎,这是好事,但是这部分访客还会提出一些新问题,尤其是技术问题,但是可能文章中提到的技术细节你已经淡忘,这时候会让你很难办。最好的做法还是还是禁用旧文章的评论,以下SQL将禁止2009-01-01之前发表的所有文章的评论,你可以根据需要修改日期:

UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2009-01-01' AND post_status = 'publish';

(2) 关闭所有文章的评论:
有时候很不幸,在不可抗力的威胁下,你不得不关闭所有文章的评论,可以使用以下SQL语句:

UPDATE wp_posts SET comment_status = 'closed' WHERE post_status = 'publish';

推荐学习:《WordPress教程

The above is the detailed content of [Organize and share] Detailed explanation of how to batch modify article information in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:ludou.org. If there is any infringement, please contact admin@php.cn delete
Previous article:What can WordPress do? Next article:What can WordPress do?