I have a "usermeta" table in db.
and there are some columns including meta_key and meta_value.
the delivery_location(meta_key) has same meta_value.
so I want to replace current meta_value to new value in deliery_location
(70982, 20, 'delivery_location', 'a:61:{i:0;s:47:"{lat:32.89030473256227, lng:-96.96264851172401}";i:1;s:47:"{lat:32.89359300394015, lng:-96.94936752319336}";i:60;s:0:"";}'),
my question is that how I can replace the all same meta_values at once in mysql?
You can get all users using get_users(). check the below code. code goes in your active theme functions.php file.
function update_all_user_delivery_location(){
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach ( $users as $key => $user ) {
$delivery_location = get_post_meta( $user->ID, 'delivery_location', true );
// modify your code here
update_post_meta( $user->ID, 'delivery_location', $delivery_location );
}
}
add_action( 'init', 'update_all_user_delivery_location', 10, 1 );