最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - SQL query to change custom field in Wordpress database

programmeradmin2浏览0评论

I'm newbie in SQL questions, and today i have a big problem.

I need change many fields in my SQL, about 4,5k. But have some rules to the query change, to don't change wrong fields where don't need changed.

In table wp_postmeta i have four columns: meta_id | post_id | meta_key | meta_value

I need change the value of meta_value, BUT ONLY if the current value is 'Y' or 'Empty' and REPLACE to value 'X', AND ONLY in lines where meta_key value is old_price

How i can do it?

I'm newbie in SQL questions, and today i have a big problem.

I need change many fields in my SQL, about 4,5k. But have some rules to the query change, to don't change wrong fields where don't need changed.

In table wp_postmeta i have four columns: meta_id | post_id | meta_key | meta_value

I need change the value of meta_value, BUT ONLY if the current value is 'Y' or 'Empty' and REPLACE to value 'X', AND ONLY in lines where meta_key value is old_price

How i can do it?

Share Improve this question asked Jan 1, 2020 at 22:05 Felipe GarciaFelipe Garcia 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Recommend a database backup before you do this.

** updated the statement to specify "Y", empty string, or null **

global $wpdb;
$wpdb->query( "update {$wpdb->postmeta} SET meta_value = 'X' WHERE meta_key = 'old_price' AND ( meta_value = 'Y' OR meta_value = '' OR meta_value IS NULL ) );" );
发布评论

评论列表(0)

  1. 暂无评论