1

I am trying to add meta_key and meta_value for the all already registered user in my database via phpmyadmin.

I want: meta_key = is_activated and meta_value = 1 enter image description here

Thanks,

1

Add this code in functions.php. visit your site you, it will automatic add/update all user meta value. After executing this code just comment out or remove this code.

$args = array(
  'fields'       => 'all',
 );
$blogusers = get_users( $args);
foreach($blogusers as $key => $user){
  update_user_meta( $user->ID, 'is_activated', 1 );
}

OR you can also do this using $wpdb

global $wpdb;
$users = $wpdb->get_results( "SELECT ID FROM $wpdb->users" );
if( $users ) {
  foreach ( $users as $user ) {
    update_user_meta( $user->ID, 'is_activated', 1 );
  }
}

check PHPMyAdmin you will find every user meta_key=is_activated is set to 1.

  • Many Thanks. I used your first code.It works fine. – Nitish Paswan Mar 8 '17 at 10:30

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