• Hi,
    Iam trying add a user meta city appended to Name column in the users list in admin section. I tried below. If I define a new column City and add content, it displays City column with data. But city do not get displayed along with data in Name column. I am modifying the functions php code. City user meta data has been added for users elsewhere.

    add_filter('manage_users_columns', 'manage_users_lstcolumns');
    function manage_users_lstcolumns($columns) {
    	$columns['name'] = 'Name';
    	$columns['city'] = 'City';
    	return $columns;
    }
    
    add_action('manage_users_custom_column',  'manage_users_lstdisplay', 10, 3);
    function manage_users_lstdisplay($value, $column_name, $user_id) {
    	if ( 'name' == $column_name )
    		return $value . '<br/>'. get_user_meta('city', $user_id);
    	if ( 'city' == $column_name )
    		return get_user_meta('city', $user_id);
        	return $value;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Try changing
    get_user_meta('city',$user_id) to
    get_user_meta($user_id,'city',true)

    Thread Starter se.srikanth

    (@sesrikanth)

    @dfunkydog,

    I tried with and without the third parameter as true. no improvement. with get_the_author_meta in place of get_user_meta displays content atleast in the city column. but Name column remains unchanged. here is my updated code.

    add_filter('manage_users_columns', 'manage_users_lstcolumns');
    function manage_users_lstcolumns($columns) {
    	$columns['name'] = 'Name';
    	$columns['city'] = 'City';
    	return $columns;
    }
    
    add_action('manage_users_custom_column',  'manage_users_lstdisplay', 10, 3);
    function manage_users_lstdisplay($value, $column_name, $user_id) {
    	if ( 'name' == $column_name )
    		return $value . '<br/>'. get_the_author_meta('city', $user_id);
    	if ( 'city' == $column_name )
    		return get_the_author_meta('city', $user_id, true);
        	return $value;
    }
    Thread Starter se.srikanth

    (@sesrikanth)

    Sorry, I was confused and my previous reply was confused.
    a. get_user_meta($user_id,’city’,true) in the new column City gets displayed. But do not affect the existing name column. Name column gets affected to the extent the column heading can be set to whatever you like but not the column data.
    b. get_the_author_meta(‘city’, $user_id) also behaves same way but the exiting Name column data do not get affected.

    c. iam looking at a way to modify/append existing column data in users list.

    d. the modifications are done in a the trhema function file and not in a plugin file. Is that the reason it do not get reflected ?

    I will be grateful for any pointers to a solution. thanks.

    Hello, did you figured out how to solve this?
    I’m having exactly the same problem. I’m trying to display my user’s city in a column, but it’s currently displaying the city’s ID, I need to display the name of the city and for that I was trying to use the filter ‘manage_users_custom_column’ but it looks like it doesn’t work anymore.

    Anyone knows if that filter is still supported? there’s no documentation about it either.

    Thanks.

    Thread Starter se.srikanth

    (@sesrikanth)

    I did manage to display new column with data, but no luck with existing columns. my final code looks like below. I am displaying ‘institute’ and ‘phoneno’ meta fields as ‘Contact Details’ column. I wish i could append and display ‘Contact Details’ data to existing column Name data.

    add_filter('manage_users_columns', 'add_user_columns', 15, 1);
    add_action('manage_users_custom_column', 'add_custom_user_columns', 15, 3);
    
    function add_user_columns( $defaults ) {
    	$defaults['details'] = __('Contact Details', 'user-column');
        return $defaults;
    }
    function add_custom_user_columns($value='', $column_name, $id) {
          if( $column_name == 'details' ) {
    		$tmpdata = get_the_author_meta( 'institute', $id );
    		$phoneno = get_the_author_meta( 'phoneno', $id );
    		if ($phoneno)
    			$tmpdata .= ($tmpdata ? '<br/>Ph: ': 'Ph: '). $phoneno;
    		return $tmpdata;
          }
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Users List: Modify existing content, manage_users_custom_column’ is closed to new replies.