sql 这些是用于更新WordPress数据库中的URL的各种SQL查询。这些查询假设表前缀是标准的`wp_`

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 这些是用于更新WordPress数据库中的URL的各种SQL查询。这些查询假设表前缀是标准的`wp_`相关的知识,希望对你有一定的参考价值。

/* Replaces URL in WordPress Home and Site URL in wp_options */
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';

/* Replaces URL in GUID of all posts/cpt/etc */
/* https://deliciousbrains.com/wordpress-post-guids-sometimes-update/ */
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');

/* Replaces URL within all posts/cpt/etc content */
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL within all posts/cpt/etc metadata */
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.oldsite.com', 'http://www.newsite.com');


/* Replaces URL in WordPress Links */
UPDATE wp_links SET link_url = replace(link_url, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL in WordPress Image Links */
UPDATE wp_links SET link_image = replace(link_image, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL in WordPress Users Website URL */
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL in WordPress Comment Authors */
UPDATE wp_comments SET comment_author_url = REPLACE(comment_author_url, 'http://www.oldsite.com', 'http://www.newsite.com');
/* Set our Old and New URLS */
SET @oldurl := "http://www.oldsite.com";
SET @newurl := "http://www.newsite.com";

/* Replaces URL in WordPress Home and Site URL in wp_options */
UPDATE wp_options SET option_value = replace(option_value, @oldurl, @newurl) WHERE option_name = 'home' OR option_name = 'siteurl';
 
/* Replaces URL in GUID of all posts/cpt/etc */
/* https://deliciousbrains.com/wordpress-post-guids-sometimes-update/ */
UPDATE wp_posts SET guid = replace(guid, @oldurl, @newurl);
 
/* Replaces URL within all posts/cpt/etc content */
UPDATE wp_posts SET post_content = replace(post_content, @oldurl, @newurl);
 
/* Replaces URL within all posts/cpt/etc metadata */
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldurl, @newurl);
 
/* Replaces URL in WordPress Links */
UPDATE wp_links SET link_url = replace(link_url, @oldurl, @newurl);
 
/* Replaces URL in WordPress Image Links */
UPDATE wp_links SET link_image = replace(link_image, @oldurl, @newurl);
 
/* Replaces URL in WordPress Users Website URL */
UPDATE wp_usermeta SET meta_value = replace(meta_value, @oldurl, @newurl);
 
/* Replaces URL in WordPress Comment Authors */
UPDATE wp_comments SET comment_author_url = REPLACE(comment_author_url, @oldurl, @newurl);

以上是关于sql 这些是用于更新WordPress数据库中的URL的各种SQL查询。这些查询假设表前缀是标准的`wp_`的主要内容,如果未能解决你的问题,请参考以下文章

sql 批量更新mysql中的WordPress帖子状态

将 .sql 数据库迁移到 WordPress

PHP 中的 SQL 查询(WordPress)

如何在 SQL 数据库中访问自定义 wordpress 邮箱的内容

用于更新 MYSQL 数据库的 PHP

移动应用程序中的 Wordpress 数据库访问