0

I have a table with 4 values, meta_id, post_id, meta_key and meta_value, and I want to change all meta_values found as "yes" to "si" when the meta_key is stock_available... how do I do this?. I cannot even retrieve the rows at this point...I'm trying with something like this.

SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` AND `meta_value` = 'yes'

Could I have some help?

EDIT: I had forgotten the meta_key...

SELECT * FROM `wp_postmeta` WHERE `meta_key` = 'stock_available' AND `meta_value` =  yes'

So I retrieve these... btu how do I update them?

1
  • You must provide a condition for 'meta_key', for example SELECT meta_value FROM wp_postmeta WHERE meta_key = 'somekey' AND meta_value = 'yes' Commented Jul 19, 2011 at 15:23

2 Answers 2

1

You need to use the SQL UPDATE statement:

UPDATE wp_postmeta SET meta_value = 'si' WHERE meta_value = 'yes' AND meta_key = 'stock_available'

Before you do that, run this SELECT to make sure that you are going to be updating the correct rows:

SELECT * FROM wp_postmeta WHERE meta_value = 'yes' AND meta_key = 'stock_available'
Sign up to request clarification or add additional context in comments.

1 Comment

that was it, thanks a lot... I need 11 minutes to accept the answer. I'llbe back then
1
UPDATE wp_postmeta
    SET meta_value = 'si'
    WHERE meta_key = 'stock_available'
        AND meta_value = 'yes';

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.