Table of Contents
1. Modify article content in batches:
2. Modify the article summary in batches:
3. Batch modify the authors of articles:
4、批量修改文章评论者的网站URL:
5、禁用所有文章的pingback功能:
6、删除所有文章的修订版:
7、删除某个评论者的所有评论:
8、替换所有评论中的敏感词汇:
9、关闭文章评论功能
Home CMS Tutorial WordPress [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

Mar 10, 2023 pm 08:10 PM
php wordpress

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 default wp_ 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, click Execute, 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, '露兜博客', '露兜中文博客' );
Copy after login

This statement The function is to replace the words Pandan Blog in all articles with Pandan 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');
Copy after login

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';
Copy after login

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, '露兜博客', '露兜中文博客' );
Copy after login

The function of this statement is to replace all the words Pandan Blog in all article summaries with Pandan 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;
Copy after login

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;
Copy after login

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;
Copy after login

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

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

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

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

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

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

UPDATE wp_posts 
SET ping_status = 'closed';
Copy after login

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';
Copy after login

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

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

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

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

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

DELETE from wp_comments 
WHERE comment_author = 'example';
Copy after login

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

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

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

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

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

9、关闭文章评论功能

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

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

UPDATE wp_posts 
SET comment_status = &#39;closed&#39; WHERE post_date < &#39;2009-01-01&#39; AND post_status = &#39;publish&#39;;
Copy after login

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

UPDATE wp_posts 
SET comment_status = &#39;closed&#39; WHERE post_status = &#39;publish&#39;;
Copy after login

推荐学习:《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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

What are the plugins for wordpress blocking ip What are the plugins for wordpress blocking ip Apr 20, 2025 am 08:27 AM

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to write a header of a wordpress How to write a header of a wordpress Apr 20, 2025 pm 12:09 PM

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

What to do if there is an error in wordpress What to do if there is an error in wordpress Apr 20, 2025 am 11:57 AM

WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.

How to change the head image of the wordpress theme How to change the head image of the wordpress theme Apr 20, 2025 am 10:00 AM

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance &gt;Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

How to display wordpress comments How to display wordpress comments Apr 20, 2025 pm 12:06 PM

Enable comments in WordPress website: 1. Log in to the admin panel, go to "Settings" - "Discussions", and check "Allow comments"; 2. Select a location to display comments; 3. Customize comments; 4. Manage comments, approve, reject or delete; 5. Use &lt;?php comments_template(); ?&gt; tags to display comments; 6. Enable nested comments; 7. Adjust comment shape; 8. Use plugins and verification codes to prevent spam comments; 9. Encourage users to use Gravatar avatar; 10. Create comments to refer to

See all articles