Home >CMS Tutorial >WordPress >Batch replace text in WordPress posts

Batch replace text in WordPress posts

藏色散人
藏色散人forward
2021-07-26 16:04:122935browse

Batch replace text in WordPress posts

Batch replace text in WordPress articles

If you plan to replace and modify the same text scattered in a large number of WordPress articles, manually edit the article modification work If the volume is large, you can use the following code to implement batch replacement. The WordPress operating data constant $wpdb will be used to modify the database, and there is no need to log in to the database for operation.

Add the code to the end of the current theme function template functions.php:

global $wpdb;
$wpdb->query("UPDATE wp_posts SET post_content = replace( post_content, '旧文字', '新文字' )");

Modify the text, if there are multiple paragraphs of text, just copy a few more pieces of code, add it to functions.php, use Then delete it.

Tip: There are risks in operating the database, please make a backup in advance!

For more WordPress technical articles, please visit the WordPress tutorial column!

The above is the detailed content of Batch replace text in WordPress posts. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zmingcx.com. If there is any infringement, please contact admin@php.cn delete