Created
June 12, 2012 06:37
-
-
Save leftlane/2915638 to your computer and use it in GitHub Desktop.
Add a meta_key to all WordPress users of Subscriber Role using add_user_meta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Create the WP_User_Query object | |
$wp_user_query = new WP_User_Query( array( 'role' => 'subscriber' ) ); | |
// Get the users | |
$users = $wp_user_query->get_results(); | |
// Check for users | |
if (!empty($users)) | |
{ | |
// Loop through each user | |
foreach ($users as $user) | |
{ | |
// Add the meta_key and the value | |
add_user_meta($user->ID, 'name_of_new_meta_key', 'value_of_meta_key', false); | |
} | |
} else { | |
echo 'No users found.'; | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment