Skip to main content
added 7 characters in body
Source Link
RiddleMeThis
  • 3.8k
  • 8
  • 21
  • 30

yes, you would have to loop through all users so that you could then update that user_meta field:

// 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
    }
}

as far as adding this same user_meta to new users you could hook into the login or registration, depending on how you are adding them to the system. for this you could use get_current_user_id() to get the id of that unique user.

later, you could then just update_user_meta($user_id,'points'); in whatever function they are earning more points at.

you can find more info on the WP_User_Query in the Codex

yes, you would have to loop through all users so that you could then update that user_meta field:

// 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
    }

as far as adding this same user_meta to new users you could hook into the login or registration, depending on how you are adding them to the system. for this you could use get_current_user_id() to get the id of that unique user.

later, you could then just update_user_meta($user_id,'points'); in whatever function they are earning more points at.

you can find more info on the WP_User_Query in the Codex

yes, you would have to loop through all users so that you could then update that user_meta field:

// 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
    }
}

as far as adding this same user_meta to new users you could hook into the login or registration, depending on how you are adding them to the system. for this you could use get_current_user_id() to get the id of that unique user.

later, you could then just update_user_meta($user_id,'points'); in whatever function they are earning more points at.

you can find more info on the WP_User_Query in the Codex

Source Link

yes, you would have to loop through all users so that you could then update that user_meta field:

// 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
    }

as far as adding this same user_meta to new users you could hook into the login or registration, depending on how you are adding them to the system. for this you could use get_current_user_id() to get the id of that unique user.

later, you could then just update_user_meta($user_id,'points'); in whatever function they are earning more points at.

you can find more info on the WP_User_Query in the Codex