2

I added custom columns but now I don't know how to get the date from the fields to show... and I have an error in my code. Can someone help?

Thanks

Here's the code :

function new_modify_user_table( $column ) {
    $column['les-non-specialistes'] = 'Non-spécialiste';
    $column['specialistes'] = 'Spécialiste';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );
    switch ($column_name) {
        case 'les-non-specialistes' :
            return get_the_author_meta( 'les-non-specialistes', $user_id );
            break;
        case 'specialistes' :
            return '';
            break;
        default:
    }
    return $return;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

enter image description here

1 Answer 1

1

To fix the error, you can do something like this:

 function new_modify_user_table_row( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );
    switch ($column_name) {
        case 'les-non-specialistes' :
            return get_the_author_meta( 'les-non-specialistes', $user_id );
            break;
        case 'specialistes' :
            return '';
            break;
        default:
    }
    return $val; //<-- Changed
  }

Regarding the date, which date are you looking for? Which column should it go into (a new one)?

I'll take a guess - I hope this gets you started. In general, say if you want to add the last modified date, you can do something like this (untested code):

case 'last-modified': //<-- new column that maybe you added above
  global $post;
  $ugly_date = $post->post_modified;
  $pretty_date = date("Y, M, jS",strtotime($ugly_date)); //<-- format as desired.  There are smarter ways of doing this part
  return $pretty_date;
  break;

(reference: http://codex.wordpress.org/Function_Reference/$post)

Good luck,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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