admin管理员组

文章数量:1332881

Our registration form has a custom field for Hospital Name. In SQL wp_usermeta the meta_key is user_registration_hospital. I have tested a number of snippets in the functions.php file to add a "Hospital" column to the Users admin table, all of which create the Hospital column in the Users list. This is one of the snippets that adds the Hospital column:

function add_user_columns($column) {
   $column['hospital'] = 'Hospital';
   return $column;
}
add_filter( 'manage_users_columns', 'add_user_columns' );

What code do I need to add to the functions.php file to have the Hospital data from wp_usermeta populate the Hospital column?

Our registration form has a custom field for Hospital Name. In SQL wp_usermeta the meta_key is user_registration_hospital. I have tested a number of snippets in the functions.php file to add a "Hospital" column to the Users admin table, all of which create the Hospital column in the Users list. This is one of the snippets that adds the Hospital column:

function add_user_columns($column) {
   $column['hospital'] = 'Hospital';
   return $column;
}
add_filter( 'manage_users_columns', 'add_user_columns' );

What code do I need to add to the functions.php file to have the Hospital data from wp_usermeta populate the Hospital column?

Share Improve this question edited Jun 29, 2020 at 20:43 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 29, 2020 at 12:54 spamisspamis 113 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

Use the following code to add new column and show data properly.

function add_user_columns_hospital( $column ) {
    $column['hospital'] = 'Hospital';
    return $column;
}
add_filter( 'manage_users_columns', 'add_user_columns_hospital' );

function modify_user_table_row_hospital( $val, $column_name, $user_id ) {
    switch ($column_name) {
        case 'hospital' :
            return get_the_author_meta( 'user_registration_hospital', $user_id );
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

本文标签: How do I create a column in Users list and display user data from custom registration field