简体   繁体   中英

Wordpress Mysql database find and replace - Replace only content based on parent

Not super skilled at MySQL commands. I am used to running commands in MySQL similar to

UPDATE wp_posts SET post_content = REPLACE (post_content,'Item to replace here','Replacement text here'); 

for finding old URLs and various small pieces of content. But this command searches ALL of my posts, and finds/replaces. I want an argument that only finds/replaces content based on the parent. I'm trying something to the effect of:

UPDATE wp_posts 
SET post_content 
WHERE post_parent = 4860
= REPLACE (post_content,'old content','new content');

without much luck. What am I doing wrong?

更新wp_posts SET post_content = REPLACE(post_content,“旧内容”,“新内容”),post_parent = 4860;

This is a common sql script that I use for updating domains in a standard WordPress install. I think this is what you're trying to do right?

-- Update common tables:

UPDATE wp_usermeta SET meta_value = replace(meta_value, 'foo.local.com', 'foo.com');

-- To update WordPress options with the new blog location, use the following SQL command:

UPDATE wp_options SET option_value = replace(option_value, 'http://foo.local.com', 'http://foo.com') WHERE option_name = 'home' OR option_name = 'siteurl';

-- After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:

UPDATE wp_posts SET guid = replace(guid, 'http://foo.local.com','http://foo.com');

-- If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:

UPDATE wp_posts SET post_content = replace(post_content, 'http://foo.local.com', 'http://foo.com');

-- If you have custom menu urls defined with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal menue links to own blog in all WordPress posts and pages:

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://foo.local.com', 'http://foo.com');

Remember, if you're trying this on a WP multisite install, there will be additional tables to convert. Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM