2

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'.

  • 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
5

Why doesn't this work?

UPDATE wp_postmeta 
SET meta_value = REPLACE( meta_value, '$', '' ) 
WHERE meta_key LIKE 'price';
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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