0

What am I doing wrong with this query? (Friday afternoon brain freeze...)

In WordPress, I used a MySQL query to make an empty custom field called "description" in all posts of a test database, and now I want to add the value "test" to that field. (This is all in the process of teaching myself how to write more complex queries.)

But I can't get this query to deal with the fact that the field has no value. 'NULL' doesn't work (and it appears that or IS NULL is what I should be using, according to other stackoverflow answers), and '%' doesn't.

UPDATE `wp_postmeta` SET `meta_value` = replace(meta_value, 'IS NULL', 'test') WHERE `meta_key` LIKE 'description'

2 Answers 2

3

I think you want

UPDATE `wp_postmeta` SET `meta_value` = 'test'
 WHERE `meta_key` LIKE 'description'
   and `meta_value` is null
Sign up to request clarification or add additional context in comments.

2 Comments

Nice - that works great. Thanks! You must have beaten Noah by only a few seconds....
yes, I did. I found out his post was 20 seconds after mine when I was double checking my answer. I guess I got lucky :)
1

You could try:

UPDATE `wp_postmeta` 
SET `meta_value` = 'test'
WHERE `meta_key` LIKE 'description'
AND `meta_value` IS NULL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.