Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For all the "price" custom fields of a site, the dollar sign was entered with the value. I need to remove the dollar sign and leave the just the values.

I know very little about SQL queries. The values are all different, so I was hoping I could use UPDATE and the wildcard to effectively delete the dollar sign, but alas, I can't make it happen.

This is what I'm trying to achieve

UPDATE wp_postmeta SET meta_value = replace(meta_value, '$%', '%') WHERE meta_key LIKE 'price'.

share|improve this question
    
I do not know that from the top of my head, but I'm sure you can look that up in the MySQL manual: dev.mysql.com/doc/refman/5.5/en –  hakre Jan 10 '11 at 15:47
    
Are you trying to update all instances of the meta_value for all posts? Or is this something that happens within a theme/plugin? –  sanchothefat Jan 10 '11 at 16:16
    
Additional note: If you're adding in the currency you'd be better off using another custom field for it, just in case you wanted extra currencies some day. –  sanchothefat Jan 10 '11 at 18:37
add comment

1 Answer

Why doesn't this work?

UPDATE wp_postmeta 
SET meta_value = REPLACE( meta_value, '$', '' ) 
WHERE meta_key LIKE 'price';
share|improve this answer
    
Maybe it will work goldenapples. So that will simply stip the dollar sign and leave the rest of the value? –  flippWP Jan 14 '11 at 23:36
    
Yeah, it should. No reason to leave a wildcard in there (and I don't think you can use a wildcard in the replace field) –  goldenapples Jan 14 '11 at 23:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.