Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the manage_users_columns to display a custom field I create in the usermeta database called company. My code is as follows:

function mysite_column_company( $defaults ) {
 $defaults['mysite-usercolumn-company'] = __('Company', 'user-column');
  return $defaults;
 }
 function mysite_custom_column_company($value, $column_name, $id) {
  if( $column_name == 'mysite-usercolumn-company' ) {
        return get_usermeta($id, 'company');
  }
 }

add_action('manage_users_custom_column', 'mysite_custom_column_company', 15, 3);
add_filter('manage_users_columns', 'mysite_column_company', 15, 1);

I'd like to get to display two other custom fields, but can't figure out the proper function. Duplicating this one doesn't work and I've not had any luck adding new functions within this one for each unique column, mostly because I can't seem to figure out how to properly define the $defaults variable. Any suggestions?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

hummm... do you mean something like this :

function mysite_column_company( $defaults ) {
    $defaults['mysite-usercolumn-company'] = __('Company', 'user-column');
    $defaults['mysite-usercolumn-otherfield1'] = __('Other field 1', 'user-column');
    $defaults['mysite-usercolumn-otherfield2'] = __('Other field 2', 'user-column');
    return $defaults;
}
function mysite_custom_column_company($value, $column_name, $id) {
    if( $column_name == 'mysite-usercolumn-company' ) {
        return get_the_author_meta( 'company', $id );
    }
    elseif( $column_name == 'mysite-usercolumn-otherfield1' ) {
        return get_the_author_meta( 'otherfield1', $id );
    }
    elseif( $column_name == 'mysite-usercolumn-otherfield2' ) {
        return get_the_author_meta( 'otherfield2', $id );
    }
}

by the way, you should use get_the_author_meta() instead of get_usermeta() as it is deprecated.

share|improve this answer
    
Meric -- works, thanks! –  John Chandler Dec 28 '10 at 3:49
    
Also get_user_meta (with a space) is perfectly fine.. –  t31os Dec 28 '10 at 13:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.