Title: Column sort not working
Last modified: August 21, 2016

---

# Column sort not working

 *  [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/column-sort-not-working/)
 * Hi,
 * I installed the plugin yesterday, and noticed that the column sorting function
   isn`t working as expected. The list of users is ordered only by the user name
   instead of last login date. Many of my users have logged in since the install
   so some of them are having actual dates shown, so theoretically it should be 
   making some sorting.
 * Best Regards,
    Csaba Czompo
 * [http://wordpress.org/extend/plugins/wp-last-login/](http://wordpress.org/extend/plugins/wp-last-login/)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/column-sort-not-working/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/column-sort-not-working/page/2/?output_format=md)

 *  [RyanThaDude](https://wordpress.org/support/users/ryanthadude/)
 * (@ryanthadude)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815544)
 * I’m also noticing this issue as well as it’s not sorting as expected. It is acting
   like I’m sorting the names instead of the dates. This was the reason for using
   this plugin.
 *  Plugin Author [Konstantin Obenland](https://wordpress.org/support/users/obenland/)
 * (@obenland)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815545)
 * Do you guys have any other user- or member-oriented plugin installed?
 * Thanks,
    Konstantin
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815546)
 * Yes I have Cimy User Extra Fields.
 *  Plugin Author [Konstantin Obenland](https://wordpress.org/support/users/obenland/)
 * (@obenland)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815547)
 * If you deactivate that plugin, does the sorting work then?
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815548)
 * No. Seemingly it`s not a plugin conflict, because on a smaller site with 4 users(
   with different login dates) even if I deactivate all plugins (Cimy included),
   the sort is taking place for the user names.
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815549)
 * A bit dirtier working alternative I`ve come up with is:
 *     ```
       add_action('pre_user_query','wpse_27518_pre_user_query');
       function wpse_27518_pre_user_query($user_search) {
           global $wpdb,$current_screen;
   
           if ( 'users' != $current_screen->id )
               return;
   
           $vars = $user_search->query_vars;
   
           if('wp-last-login' == $vars['orderby'])
           {
               $user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key='wp-last-login')";
               $user_search->query_orderby = ' ORDER BY UPPER(m1.meta_value) '. $vars['order'];
           }
       }
       ```
   
 *  [ds123](https://wordpress.org/support/users/ds123/)
 * (@ds123)
 * [13 years ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815550)
 * i’m using buddypress and sorting is not working
 *  [ds123](https://wordpress.org/support/users/ds123/)
 * (@ds123)
 * [12 years, 12 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815551)
 * i’d like to use this plugin to help me weed out the inactive accounts on my site….
   can you please post the mysql query that will query the database and return a
   list of usernames and date of last login …sorted from most recent login on down?
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [12 years, 12 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815552)
 * The code above, when pasted into your functions.php file does the exact same 
   thing … it makes the login date column sortable.
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [12 years, 12 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815553)
 * You can even schedule a daily automatic delete of unused accounts, specifying
   the max. days without login, like so (to be put in functions.php):
 *     ```
       add_action('mydailyclearout', 'deleteinactiveusers');
   
       function my_activation() {
       if( !wp_next_scheduled( 'mydailyclearout' ) ) {
        wp_schedule_event(time(), 'daily', 'mydailyclearout');
        }
       }
   
       add_action('wp', 'my_activation');
   
       function deleteinactiveusers() {
       	  $days = 60; // days without login
       	  $meta_value = time() - ($days * 24 * 60 * 60);
       	  $user_query = new WP_User_Query(
       	    array(
       			'meta_key'       => 'wp-last-login',
       			'meta_value'     => $meta_value,
       			'meta_compare'   => '<',
       			'meta_type'      => 'NUMERIC'
       		    )
       	     );
   
         	  $users = $user_query->results;
            if (!empty($users)){
       	foreach( $users as $user ) {
       	 if ($user->roles[0] =="subscriber"){	// only delete subscribers
                 $user_email = stripslashes($user->user_email);
       	  $user_name = $user->user_login;
       	  $headers = array("Content-Type: text/html; charset=UTF-8");
       	  wp_mail($user_email, $user_name . " unused account deleted",'Your unused account <strong>' . $user_name . '</strong> has been deleted.',$headers); // send an email notification
                 wp_delete_user($user->ID); // delete the user
       	 }
       	}
              }
   
         $days=50; // you can even send a notification several days before for their consideration
       	  $meta_value1 = time() - ($days * 24 * 60 * 60);
       	  $meta_value2 = time() - (($days+1) * 24 * 60 * 60);
       	  $user_query = new WP_User_Query(
       	    array(
       			'meta_key'       => 'wp-last-login',
       			'meta_value'     => array($meta_value2,$meta_value1),
       			'meta_compare'   => 'BETWEEN',
       			'meta_type'      => 'NUMERIC'
       		    )
       	     );
   
         	  $users = $user_query->results;
            if (!empty($users)){
              foreach( $users as $user ) {
       	 if ($user->roles[0] =="subscriber"){
       	  $user_email = stripslashes($user->user_email);
       	  $user_name = $user->user_login;
       	  $headers = array("Content-Type: text/html; charset=UTF-8");
       	  wp_mail($user_email, "Important! ". $user_name . " account is scheduled to be deleted",'More then ' . $days . ' have passed since your last login with <strong>' . $user_name . '</strong> username. If you dont login in several days your account will be deleted',$headers); // send notification email
       	 }
              }
          }
       }
       ```
   
 * I`m using this with success on my site, but for security you should test it out
   first on a nonproduction site first.
    On a side note, this won`t list/delete 
   those users to have never logged in or only before first plugin activation. For
   them you have to do the job manually.
 *  Thread Starter [czcsabi](https://wordpress.org/support/users/czcsabi/)
 * (@czcsabi)
 * [12 years, 12 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815554)
 * For the wp_delete_user function to properly work I had to include the user.php
   file like so:
    require_once( ABSPATH.’wp-admin/includes/user.php’ ); The modified
   code is:
 *     ```
       add_action('mydailyclearout', 'deleteinactiveusers');
   
       function my_activation() {
       if( !wp_next_scheduled( 'mydailyclearout' ) ) {
        wp_schedule_event(time(), 'daily', 'mydailyclearout');
        }
       }
   
       add_action('wp', 'my_activation');
   
       function deleteinactiveusers() {
       	  $days = 60; // days without login
       	  $meta_value = time() - ($days * 24 * 60 * 60);
       	  $user_query = new WP_User_Query(
       	    array(
       			'meta_key'       => 'wp-last-login',
       			'meta_value'     => $meta_value,
       			'meta_compare'   => '<',
       			'meta_type'      => 'NUMERIC'
       		    )
       	     );
   
         	  $users = $user_query->results;
            if (!empty($users)){
               require_once( ABSPATH.'wp-admin/includes/user.php' ); // this had to be added for the wp_delete_user function to work properly
       	foreach( $users as $user ) {
       	 if ($user->roles[0] =="subscriber"){	// only delete subscribers
                 $user_email = stripslashes($user->user_email);
       	  $user_name = $user->user_login;
       	  $headers = array("Content-Type: text/html; charset=UTF-8");
       	  wp_mail($user_email, $user_name . " unused account deleted",'Your unused account <strong>' . $user_name . '</strong> has been deleted.',$headers); // send an email notification
                 wp_delete_user($user->ID); // delete the user
       	 }
       	}
              }
   
         $days=50; // you can even send a notification several days before for their consideration
       	  $meta_value1 = time() - ($days * 24 * 60 * 60);
       	  $meta_value2 = time() - (($days+1) * 24 * 60 * 60);
       	  $user_query = new WP_User_Query(
       	    array(
       			'meta_key'       => 'wp-last-login',
       			'meta_value'     => array($meta_value2,$meta_value1),
       			'meta_compare'   => 'BETWEEN',
       			'meta_type'      => 'NUMERIC'
       		    )
       	     );
   
         	  $users = $user_query->results;
            if (!empty($users)){
              foreach( $users as $user ) {
       	 if ($user->roles[0] =="subscriber"){
       	  $user_email = stripslashes($user->user_email);
       	  $user_name = $user->user_login;
       	  $headers = array("Content-Type: text/html; charset=UTF-8");
       	  wp_mail($user_email, "Important! ". $user_name . " account is scheduled to be deleted",'More then ' . $days . ' have passed since your last login with <strong>' . $user_name . '</strong> username. If you dont login in several days your account will be deleted',$headers); // send notification email
       	 }
              }
          }
       }
       ```
   
 *  [taras_bulba](https://wordpress.org/support/users/taras_bulba/)
 * (@taras_bulba)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815557)
 * Column sorting is definitely not working.
 * I don’t have any other plugin that works with the users data.
 * I’ve tried this: [http://wordpress.org/support/topic/admin-column-sorting?replies=14](http://wordpress.org/support/topic/admin-column-sorting?replies=14)
 * and this: [http://j3webworks.com/blog/wordpress-add-and-sort-custom-column-in-users-admin-page](http://j3webworks.com/blog/wordpress-add-and-sort-custom-column-in-users-admin-page)
 * with no luck.
 * Whatever I do, it sortb by login (username) no matter what.
 * Any idea anyone?
 * Thanks.
 *  [Nakonama](https://wordpress.org/support/users/nakonama/)
 * (@nakonama)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815558)
 * Same problem here, when click last login, it sort by the name,
 * how can we solve it ?
 * Jack
 *  [Nakonama](https://wordpress.org/support/users/nakonama/)
 * (@nakonama)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815559)
 * Any update here ?
 * will it be possible to sort the last login date ?
 * Jack
 *  [Eric Langley](https://wordpress.org/support/users/elangley/)
 * (@elangley)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/column-sort-not-working/#post-3815560)
 * Column sorting is not working for me as well. BP 1.81 and WP 3.6

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/column-sort-not-working/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/column-sort-not-working/page/2/?output_format=md)

The topic ‘Column sort not working’ is closed to new replies.

 * ![](https://ps.w.org/wp-last-login/assets/icon.svg?rev=3527809)
 * [WP Last Login](https://wordpress.org/plugins/wp-last-login/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-last-login/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-last-login/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-last-login/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-last-login/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-last-login/reviews/)

 * 20 replies
 * 8 participants
 * Last reply from: [taras_bulba](https://wordpress.org/support/users/taras_bulba/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/column-sort-not-working/page/2/#post-3815565)
 * Status: not resolved