How to add user meta for all users - WordPress Development Stack Exchange

PHOTO EMBED

Wed Sep 14 2022 01:20:41 GMT+0000 (Coordinated Universal Time)

Saved by @kalehm

// Create the WP_User_Query object
$wp_user_query = new WP_User_Query(array('role' => 'Subscriber'));

// Get the results
$users = $wp_user_query->get_results();

// Check for results
if (!empty($users)) {

    // loop trough each author
    foreach ($users as $user)
    {
        // add points meta all the user's data
        add_user_meta( $user->id, 'points', '5', true ); // 5 = number of points existing users will get
    }
}
content_copyCOPY

https://wordpress.stackexchange.com/questions/222813/how-to-add-user-meta-for-all-users