Wp-admin/users.php添加带有姓氏的列

时间:2020-06-11 作者:lefty

如何在wp admin/users中添加包含用户姓氏的附加列。php?它也应该是可排序的。

这里有一个类似的问题:https://wordpress.stackexchange.com/a/203478/181889 但我不知道如何使用过滤器。

提前感谢!

1 个回复
最合适的回答,由SO网友:ViralP 整理而成

3个步骤

  1. Add custom column
  2. Fill data in custom column
  3. 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);
编辑:响应按用户姓氏排序的能力要求

默认情况下,Wordpress不允许用户按姓氏排序。请参阅中的“orderby”部分WP_User_Query

相关推荐

Can't Reach wp-admin

访问链接上的wp admin时http://ec2-3-16-54-250.us-east-2.compute.amazonaws.com/wp-admin, 我获得以下URLhttp://ec2-3-16-54-250.us-east-2.compute.amazonaws.com/wp-admin/ec2-3-16-54-250.us-east-2.compute.amazonaws.com/wp-login.php?redirect_to=http%3A%2F%2Fec2-3-16-54-250.u