• Hi
    I have created a new user field – rpr_school_year
    and I want to add this data into a sortable column on the network admin user list
    i tried to look at the code from the last login plugin (which mimics exactly what I want to do but with school year rather than time stamp) but I am lost
    any advice
    TIA

Viewing 9 replies - 1 through 9 (of 9 total)
  • Read a tutorial here: https://pippinsplugins.com/add-user-id-column-to-the-wordpress-users-table/

    But filter wpmu_users_columns or the list will appear only in the site users rather than network users list table.

    Something like the following should be close.

    <?php
    add_filter('wpmu_users_columns', 'ds_add_user_rpr_school_year');
    function ds_add_user_rpr_school_year($columns) {
    	$columns['rpr_school_year'] = 'School Year';
    	return $columns;
    }
    
    add_action('manage_users_custom_column', 'ds_show_user_rpr_school_year', 10, 3);
    function ds_show_user_rpr_school_year($value, $column_name, $user_id) {
    	if ( 'rpr_school_year' == $column_name )
    		return get_user_meta( $user_id, 'rpr_school_year', true );
    	return $value;
    }
    ?>

    I use the following snippet to list the UserID and it works fine:

    <?php
    add_filter('wpmu_users_columns', 'ds_add_user_id_column');
    function ds_add_user_id_column($columns) {
        $columns['user_id'] = 'User ID';
        return $columns;
    }
    
    add_action('manage_users_custom_column',  'ds_show_user_id_column_content', 10, 3);
    function ds_show_user_id_column_content($value, $column_name, $user_id) {
        $user = get_userdata( $user_id );
    	if ( 'user_id' == $column_name )
    		return $user_id;
        return $value;
    }
    ?>

    Have not figured out sortable, yet.

    Sortable:

    add_filter('manage_users-network_sortable_columns', 'ds_column_sortable');
    function ds_column_sortable($columns) {
               $columns['user_id'] = 'id';
    	return $columns;
    }

    Thread Starter kgh79

    (@kgh79)

    thank you david… I had seen your tutorial but being a such a bear with a little brain I couldn’t translate it to wpmu_users_column

    Thread Starter kgh79

    (@kgh79)

    quick question david – the sort code doesnt seem to sort them on the meta value – any advice?

    It is a trick; filter the ‘request’ or add_action to ‘pre_user_query’ to make sure the request is ‘heard’ when you click on it.

    I found the method below works reliably for me

    http://www.host1plus.com/tutorials/cms-tutorials/wordpress/other-wordpress/how-to-make-extra-columns-in-user-php-sortable/

    Look in the following code/paste for where I have placed your rpr_school_year key.

    Should be a clue to get it working in your own code snippet in there somewhere.

    http://pastebin.com/PnjmEV8x

    Thread Starter kgh79

    (@kgh79)

    david thank you very much
    as a total newbie I have one last question…
    rpr_school_year has four possible entries from a drop down list (9,10,11,12, teacher)
    where do i enter that data within the code so that school year column sorts by each type? thanks so much

    Thread Starter kgh79

    (@kgh79)

    david when I do add your code – the sort this doesnt work and it also leaves my last login column next to it empty….

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    What plugin are you using for last_login? Sounds like a column conflict.

    add_action('manage_users_custom_column',  'ds_show_user_id_column_content', 10, 3);

    That’s probably clashing.

    kgh79,

    Use pastebin to show me what you have so far. I have a network with grades 9-12 students, too, so I can fiddle away till I get it right here and share what I have back to you.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Add column to network admin user list’ is closed to new replies.