I have created a special form within my site that allows my users to enter a key. I am using add_user_meta()
to add the meta data into the database. I want to be able to see this key when I click on users in the admin center.
How would I go about adding to this column?
Below is the meta data info im using
add_user_meta($userId,'code','12345');
We just want to be able to add it to the view on users.php in the table displaying username email and role.
I have used code like this to display the user id but I can not figure out how to display their meta.
add_filter('manage_users_columns', 'pippin_add_user_id_column');
function pippin_add_user_id_column($columns) {
$columns['user_id'] = 'User ID';
return $columns;
}
add_action('manage_users_custom_column', 'pippin_show_user_id_column_content', 10, 3);
function pippin_show_user_id_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'user_id' == $column_name )
return $user_id;
return $value;
}
This example was created with the help of these two pages from the WordPress codex.
https://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile
https://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
It is for displaying and updating the custom user meta data.
The answer above from Mordred worked for me after changing the second add_filter to add_action. Here’s the modified code:
To add custom user_meta fields to users.php you need to do the following:
Realising this is a bit of an old thread, however I was stuck on a very similar problem, and thought I would share what I found which proved to be a very simple solution.
Credit: https://pippinsplugins.com/add-user-id-column-to-the-wordpress-users-table/
To make the additional woocommerce fields editable you can use the following filter (in the example a custom field is added in the billing section).