I’m trying to add two columns to the users.php file. I’m not sure how to add both $total_time_display and $logged_in_amount_display. How could I return both values?
Here is my code:
add_filter('manage_users_columns', 'freeman_add_user_minutes_column');
function freeman_add_user_minutes_column($columns) {
$columns['total_time'] = 'Total Minutes';
$columns['logged_in_amount'] = 'Number of Logins';
return $columns;
}
add_action('manage_users_custom_column', 'freeman_show_user_minutes_column_content', 10, 3);
function freeman_show_user_minutes_column_content($value, $column_name, $user_id) {
$user = get_userdata( $user_id );
if ( 'total_time' == $column_name )
$total_time_display = ($user->total_time);
return $total_time_display;
if ( 'logged_in_amount' == $column_name )
$logged_in_amount_display = ($user->logged_in_amount);
return $logged_in_amount_display;
return $value;
}
Correct to use
echo
notreturn
. This is action, not the filter. And you can deletereturn $value;
from your callback.Guessing at what your meta fields are calling, implementing Oleg’s suggestions would mean updating your
freeman_show_user_minutes_column_content()
function like so:Your custom meta isn’t part of the
$user
object, so instead, you have to useget_user_meta()
.Thanks for the help buys but I ended up figuring it out. Just echoing the code did not give me the results I wanted but returning it did.
Here is the code: