• Hi there,

    I always used the following code in my function.php file to display users alphabetically:

    function sort_by_newest( $query ) {
    global $pagenow;
    if ( is_admin() && $pagenow == ‘users.php’ ) {
    if ( ! isset( $_REQUEST[‘orderby’] ) ) {
    $query->query_vars[“order”] = ‘desc’;
    $query->query_orderby = ” ORDER BY user_nicename ” . ( $query->query_vars[“order”] == “asc” ? “desc ” : “asc ” ); //set sort order
    }
    }
    return $query;
    }

    This code overrides the UM function in class-admin-users.php file.
    Unfortunately, it does not seem to work anymore after updating to version 2.0 of your plugin. How can I fix it? I need to display users in alphabetical order by default.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mykyta Synelnikov

    (@nsinelnikov)

    Hi @simobenedettidesign,

    You may use this code lines to fix this issue.

    remove_filter( ‘pre_user_query’, array( UM()->users(), ‘sort_by_newest’ ) );

    function my_custom_sort_by_newest( $query ) {
    global $pagenow;
    if ( is_admin() && $pagenow == ‘users.php’ ) {
    if ( ! isset( $_REQUEST[‘orderby’] ) ) {
    $query->query_vars[“order”] = ‘desc’;
    $query->query_orderby = ” ORDER BY user_nicename ” . ( $query->query_vars[“order”] == “asc” ? “desc ” : “asc ” ); //set sort order
    }
    }
    return $query;
    }
    add_filter( ‘pre_user_query’, ‘my_custom_sort_by_newest’ );

    Let me know if this works,
    Thanks!

    Thread Starter simobenedettidesign

    (@simobenedettidesign)

    Thanks for your quick reply. I tried to copy and paste your code in my function.php file but it does not seem to work. Users are still “sort by newest” and not “by nicename”. For some strange reason, this code in my function.php file is ignored. All other codes work perfectly. Any suggestion?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sorting users by alphabetical order’ is closed to new replies.