Hello,
I would like to add a admin column.
My code doesn't work.
//Add custom column
add_filter('manage_users_columns', 'my_columns_head');
function my_columns_head($defaults) {
$defaults['votre-sport'] = 'Sport';
return $defaults;
}
//Add rows data
add_action('manage_users_custom_column', 'my_custom_column', 10, 3 );
function my_custom_column($column, $user_id ){
switch ( $column ) {
case 'Votre sport':
echo get_user_meta($user_id, 'wpcf-votre-sport', true );
break;
}
}
Thanks
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
You mean add a column for a custom field on the backend page that lists posts of some type?
Do you know you can do that in the settings for the custom post type?
See screenshot for an example from my local site.
Hello,
No it's for Users List. It's not a post type.
Thanks
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
There are problems with your code.
The names of the columns don't match up between the two functions you have added, manage_users_custom_column is a filter not an action, and also you are using the parameters of manage_users_custom_column wrongly.
Here is a very quick version I tested on my local site for a "Team" custom user field, which works, if you want to modify your code to do something similar:
//Add custom column
add_filter('manage_users_columns', 'my_columns_head');
function my_columns_head($defaults)
{
$defaults['team'] = 'Team';
return $defaults;
}
//Add rows data
add_action('manage_users_custom_column', 'my_custom_column', 10, 3);
function my_custom_column($val, $column, $user_id)
{
switch ($column) {
case 'team':
$val = get_user_meta($user_id, 'wpcf-team', true);
break;
}
return $val;
}