特定のkeyをもったカスタムフィールドのvalueとkeyを書き換える関数です。
$query_titles = "SELECT meta_value,meta_id FROM " . $wpdb->postmeta . " WHERE meta_key = 'othercharge_title' AND post_id =". $post_id; $othercharge_titles = $wpdb->get_results($query_titles, ARRAY_A); $query_values = "SELECT meta_value,meta_id FROM " . $wpdb->postmeta . " WHERE meta_key = 'othercharge_value' AND post_id =". $post_id; $othercharge_values = $wpdb->get_results($query_values, ARRAY_A); $title = "hoge" //keyの指定 $new_value = "hoge2" //新しいvalueの設定 $new_title = "hoge3" //新しいkeyの設定 function update_value($wpdb,$othercharge_titles,$othercharge_values,$title,$new_value){ $number = array_search_recursive($title, $othercharge_titles); $query_value_update = "update wp1_postmeta set meta_value = '".$new_value."' where meta_id = ".$othercharge_values[$number]['meta_id']; $data = $wpdb->get_results($query_value_update, ARRAY_A); } function update_title($wpdb,$title,$new_title){ $query_title_update = "update wp1_postmeta set meta_value = REPLACE(`meta_value`,'".$title."','".$new_title."') where meta_key = 'othercharge_title'"; $data = $wpdb->get_results($query_title_update, ARRAY_A); }