Home › Forums › Backend Issues (wp-admin) › Admin users list – new sortable column based on custom field
HI All!
I’m struggeling with adding new column to the list view of users (users.php). At the very beginning i’ve added a relationship field (visible only for specific user roles) called opiekun_klienta (account_manager in english). It’s a dropdown list with few names.
So far i have such code:
add_filter( 'manage_users_columns', 'column_register_wpse_101322' );
add_filter( 'manage_users_custom_column', 'column_display_wpse_101322', 10, 3 );
function column_register_wpse_101322( $columns )
{
$columns['accountmanager_col'] = 'Opiekun';
return $columns;
}
function column_display_wpse_101322( $value, $column_name, $user_id )
{
$user_info = get_user_meta( $user_id, 'opiekun_klienta', true );
if($column_name == 'accountmanager_col') return $user_info;
return $value;
}
and well, it more less works. More less = its adding column, displaying values BUT only as an ID (numeric). Not exact values like text. Why?
Sounds like the value stored in your ‘opiekun_klienta’ field is the user id of the account manager, so there’s just one more step to get the display name (or whichever field you want to show for the managers).
I haven’t tested this, but this should get you close – replace the last function in your code above with:
function column_display_wpse_101322( $value, $column_name, $user_id )
{
$manager_id = get_user_meta( $user_id, 'opiekun_klienta', true );
$manager_name = get_user_meta( $manager_id, 'display_name', true);
if($column_name == 'accountmanager_col') return $manager_name;
return $value;
}
Hi @lsell ,
I have a similar thing to achieve. I used the @pawciak code to show a column in the dashboard’s users page that consists of an ACF text field:
add_filter( 'manage_users_columns', 'column_register_acf_id' );
add_filter( 'manage_users_custom_column', 'column_display_acf_id', 10, 3 );
function column_register_acf_id( $columns )
{
$columns['id_col'] = 'ID';
return $columns;
}
function column_display_acf_id( $value, $column_name, $user_id )
{
$user_info = get_user_meta( $user_id, 'czlonek_id', true );
if($column_name == 'id_col') return $user_info;
return $value;
}
czlonek_id
is my ACf field name (location: user form > equal > add/edit). However this doesn’t work – the column shows up, but the value does not.
Any advice? Thx.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.