admin管理员组文章数量:1334321
How can I add an additional column containing the last name of the user in wp-admin/users.php? It also should be sortable.
There is a similar question here: but I don't know how to work with the filter.
Thanks in advance!
How can I add an additional column containing the last name of the user in wp-admin/users.php? It also should be sortable.
There is a similar question here: https://wordpress.stackexchange/a/203478/181889 but I don't know how to work with the filter.
Thanks in advance!
Share Improve this question asked Jun 11, 2020 at 16:22 leftylefty 153 bronze badges1 Answer
Reset to default 03 Steps
- Add custom column
- Fill data in custom column
- Make the column sortable
//Add custom column
function my_custom_wp_filter_add_user_lastname_column($columns) {
$columns['user_lastname'] = 'Last Name';
return $columns;
}
add_filter('manage_users_columns', 'my_custom_wp_filter_add_user_lastname_column');
//Fill in value in custom column
function my_custom_wp_filter_add_user_lastname_column_value( $column_output, $column_name, $user_id ) {
$user = get_userdata( $user_id );
if ( 'user_lastname' == $column_name ) {
return $user->last_name;
}
return $column_output;
}
add_filter('manage_users_custom_column', 'my_custom_wp_filter_add_user_lastname_column_value', 10, 3);
//Make the column sortable
function my_custom_wp_filter_make_user_lastname_column_sortable( $colums_to_sort ) {
$colums_to_sort['user_lastname'] = 'last_name';
return $colums_to_sort;
}
add_filter('manage_users_sortable_columns', 'my_custom_wp_filter_make_user_lastname_column_sortable', 10, 1);
Edit : Response to requirement of ability to sort by user's last name
Wordpress does not allow users to be sorted by last_name by default. See 'orderby' section in WP_User_Query
本文标签: wpadminusersphp Add a column with last name
版权声明:本文标题:wp-adminusers.php Add a column with last name 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742356403a2459501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论