Support » Plugin: Simple User Listing » Sorting by firstname

  • Hi there
    I have two small questions:

    1. When I list ALL users they come up in alphabetical order, which is the way they should. But when I make a “filter” with ?as=XXXXXXXXXXXX they don’t come in alphabetical order, even if I use this code on my page:

    [userlist meta_key=”first_name” orderby=”meta_value” order=”ASC” exclude=”1″ number=”200″ userlist role=”subscriber”]

    2. Is it possible to search the users with the builtin WordPress Search form?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author helgatheviking


    1. By filter, if you mean to Search, then I cannot replicate this.

    Using this shortcode:

    [userlist role="subscriber" meta_key="first_name" orderby="meta_value" order="ASC" exclude="1" number="200"]

    Generates this page:

    If you search for “Gibson”

    They still appear in order by first name. I’d try disabling any other plugins to see if maybe there’s a conflict.

    2. I usually say everything is possible given enough time and/or resources. But know that SUL is specifically looking for an as input, where the builtin form submits s. The builtin form also is programmed to search for posts (pages and CPTs) and to display posts… not users. Users and Posts are different kinds of data. Good luck.

    1. I have installed the “Simple Intranet” Plugin, to get Department, Location, Title and so on. That works great. And with you plugin I can on the page make this shortcode:

    [userlist meta_key=”first_name” orderby=”meta_value” order=”ASC” exclude=”1″ number=”200″ userlist role=”subscriber”]

    And the page WORK 100%.

    Now – if I make a call on the page with this Search “as” – “?as=XXXXX” it searches the Title field, but not the Department.

    Plugin Author helgatheviking


    That’s now WP_User_Query works (see the docs). WP_User_Query is the foundation of SUL, so SUL is limited by what WP_User_Query can and cannot do.

    In order to search users by a meta field you’ll need to write a custom query. I have an example in my FAQ.

    Ok.. got it!

    But can I search in both Lastname and Firstname?

    Found it!

    Now I only need to remove the pagnation when searching.

    Plugin Author helgatheviking


    Yes, you can search both. You just need to set the meta query to an array of meta fields. To remove pagination, you’d need to detect when you are searching (typically I do that by detecting the $_GET['as'] is set, and setting the number parameter to null. When you’re done could you post your code?

    This is my code, that is searching FIRST name and LAST name.

     * Place this in your theme's functions.php file
     * Or a site-specific plugin
    // Switch the WP_User_Query args to a meta search
    function kia_meta_search( $args ){
      // this $_GET is the name field of the custom input in search-author.php
        $search = ( isset($_GET['as']) ) ? sanitize_text_field($_GET['as']) : false ;
        if ( $search ){
    $args  =  array ( 
            'meta_query' => array(
            'relation' => 'OR',
                'key'     => 'first_name',
                'value'   => $search,
                'compare' => 'LIKE'
                'key'     => 'last_name',
                'value'   => $search,
                'compare' => 'LIKE'
            // need to unset the original search args
            if( isset( $args['search'] ) ) unset($args['search']);
        return $args;
    add_filter('sul_user_query_args', 'kia_meta_search');

    But when using the search function, no matter id I change the orderby code: simple-user-listing.php:

    			$defaults = array(
    				'query_id' => 'simple_user_listing',
    				'role' => '',
    				'role__in' => '',
    				'role__not_in'=> '',
    				'include' => '',
    				'exclude' => '',
    				'blog_id' => '',
    				'number' => get_option( 'posts_per_page', 10 ),
    				'order' => 'ASC',
    				'orderby' => 'first_name',
    				'meta_key' => '',
    				'meta_value' => '',
    				'meta_compare' => '=',
    				'meta_type' => 'CHAR',
    				'count_total' => true,
    				'taxonomy' => '',
    				'terms' => ''

    It always orderby the login name… how can I change that?

    Plugin Author helgatheviking


    I would change the orderby in your filter and not in the plugin itself. But if it’s not working in the plugin, then unfortunately, I don’t know what else to try.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Sorting by firstname’ is closed to new replies.