Brian Milnes
Brian Milnes

Reputation: 172

SQL (via phpMyAdmin)

I want to do a Search and Replace in a WordPress posts table, but conditional on the type of posts This is what I have got, and SELECTing works but I am not sure about replacing 'old title' with 'new prefix old title'

UPDATE `wp_posts` 
WHERE `post_title` REGEXP '^old title' 
  AND `post_type` = 'download' 
set 'post_title' = replace( 'post_title', 'old title', 'new prefix old title');

Upvotes: 1

Views: 39

Answers (1)

Mureinik
Mureinik

Reputation: 311383

The set clause should come before the where clause. Also, post_title is a column name, not a string literal, so you shouldn't use single quotes ('):

UPDATE `wp_posts`
SET    `post_title` = REPLACE(`post_title`, 'old title', 'new prefix old title')
WHERE  `post_title` REGEXP '^old title' AND `post_type` = 'download'

Upvotes: 1

Related Questions