• Resolved dmitcha

    (@dmitcha)


    Thanks for this very useful plugin! I saw a couple of earlier inquiries asking how to set the default view to the most recent registrations. Although the plugin support’s current “resolved” answer is “not possible,” I did find a code snippet that neatly did the trick. Maybe it can be added to the plugin down the road.

    With many thanks to Thomas Griffin, I just added the snippet below to my child theme’s functions.php file:

    add_action( 'pre_user_query', 'tgm_order_users_by_date_registered' );
    function tgm_order_users_by_date_registered( $query ) {
        global $pagenow;
        if ( ! is_admin() || 'users.php' !== $pagenow ) {
            return;
        }
        $query->query_orderby = 'ORDER BY user_registered DESC';
    }

    https://www.ads-software.com/plugins/recently-registered/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    The reason I tag it as ‘not possible’ is that you can’t do it the way people WANT it.

    That is, you can’t really click on the header to make it do things like you can with name and email. They’re not sortable like other columns.

    The best I could do would be to make the column header a link that, when clicked, would activate that snippet. The problem would THEN be how to properly un-click. It would break user’s expectations for that screen, which I’m loathe to even consider.

    Thread Starter dmitcha

    (@dmitcha)

    Understood. From what I’ve read here and elsewhere, what a lot of people want is the default sort order to be by registration date and descending. Happily, this snippet plus your plugin manages that specific desire – and in less than five minutes!

    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Default but changeable ??

    You want to be able to resort by email, IP, or username. And since I can’t figure out how to get THAT to work… Anyway. Yes, code works, but it’s decision I’m not willing to force everyone into.

    Thread Starter dmitcha

    (@dmitcha)

    Sure. It’s perfect for those (like me) who don’t care about other sort options. And maybe someone else will come up with a way to toggle it on and off after seeing this thread. I’m glad I was able to share it with others (recognizing you yourself remain unimpressed and unappreciative, lol)!

    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I am both impressed and appreciative and will add it to the documentation ??

    I’m unimpressed with WP’s locking me out of being able to use it the way the damn columns SHOULD be used ??

    Thread Starter dmitcha

    (@dmitcha)

    haaaahahaha – you still solved the MAIN problem for most of us!

    How about adding a check for isset( $_GET['orderby'] ) to the snippet provided by dmitcha? This allows entries to be sorted by registration date by default, and by whatever column the user has clicked otherwise.

    By default, when visiting /wp-admin/users.php, $_GET['orderby'] is not set. This is our cue to allow users to be ordered by their registration date — the user has landed on the user listing admin page and has not specified their sorting preference. However, if the user *has* clicked on one of the sortable column headers (therefore setting $_GET['orderby']), then we back off and allow their desired sorting to be applied.

    add_action( 'pre_user_query', 'tgm_order_users_by_date_registered' );
    function tgm_order_users_by_date_registered( $query ) {
    	global $pagenow;
    
    	if ( ! is_admin() || 'users.php' !== $pagenow || isset( $_GET['orderby'] ) ) {
    		return;
    	}
    	$query->query_orderby = 'ORDER BY user_registered DESC';
    }
    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    TBH, I’ve been working on this since I had to add in sortable queries for another thing I was working on. I have some ideas, I just need free time ??

    Thanks for the update, and for general awesomeness! ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘One way to set the default order to: registration date, descending’ is closed to new replies.