As I refine my most popular plugin it will store a special number decoded from the user's birth date, which is an extended BuddyPress field in bp_xprofile_data. All users get a number between 1 and 260, and I will assemble a list of BuddyPress users based on this number.

It seems there's at least two established methods of storing extended user data with the usermeta table. There are 4 possible methods I can imagine:

  1. Use the BuddyPress bp_xprofile_data table
  2. Use the usermeta table
  3. Add a field to the wp_users table so that I can get user_id with the "fastest PHP in the west"
  4. Create a fresh new table for my awesome plugin

I want code that is efficient with resources of course, as there's gunna be lot's 'o doggies to corral.

Is the recommended method to insert the number into the usermeta, and retrieve it with a query, something like this?

$users_by_kin = "SELECT * 
    FROM ".$wpdb->prefix."usermeta 
    WHERE meta_key='kin_id' 
    AND meta_value='$kin_id'"

Which method is considered best WP Practices?


If you want best practices of the options you listed use the user meta table.

Adding a column to the users table would be the worst thing you could do - messing with table structure of default WP tables is a no-no.

The other two options would fall somewhere in between - with adding your own table being least preferred.

But why don't you use the WP_User_Query class?

 $user_by_kin = new WP_User_Query( 
        'meta_key' => 'kin_id', 
        'meta_value' => $kin_id, 
        'meta_compare' => '=' 
  • Thanks for the answer. As I understand it, I would add the metadata in this way... $user_id = 2; $kin_id = 139; add_user_meta( $user_id, 'kin_id', $awesome_level); – cowboy Mar 13 '15 at 17:48
  • I think that based on you showed in your original query, it would be add_user_meta( $user_id, 'kin_id', $kin_id); – butlerblog Mar 14 '15 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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