Mysql – PolyLang WP Update to replace one string to another

MySQLreplaceupdateWordpress

I have to replace one string to another one in post_content column in table wp_post ( WordPress ).
My query works only then when I use SELECT but when I want to use UPDATE command with REPLACE then I have error. My query:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'str1', 'str2') FROM wp_posts WHERE ID IN (
SELECT ID
FROM wp_posts 
WHERE ID IN (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(description, '"ar";i:', -1), ';',1) FROM wp_term_taxonomy WHERE taxonomy = 'post_translations'))

Mysql said:

#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM wp_posts WHERE ID IN (
SELECT ID
FROM wp_posts
WHERE ID IN (SELECT S…' at line 1

Best Answer

Basically, you constuction to get the right ID was doubles and UPDAT has no fROM clause

There WHERE clause you should try first in a SELECT if you get all IDs

UPDATE wp_posts 
SET post_content = REPLACE(post_content, 'str1', 'str2')  
WHERE ID IN (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(description, '"ar";i:', -1), ';',1) FROM wp_term_taxonomy WHERE taxonomy = 'post_translations')