WordPress.org

Ready to get started?Download WordPress

Forums

Simple User Listing
[resolved] orderby="user_lastname" ? (4 posts)

  1. vicksterm
    Member
    Posted 8 months ago #

    I tried this in the short code and it didn't work. Is there a way to sort by last name that I'm missing?

    http://wordpress.org/plugins/simple-user-listing/

  2. helgatheviking
    Member
    Plugin Author

    Posted 8 months ago #

    user_lastname is not one of the orderby values supported by WP_User_Query.

    I can't push it live now, but by the weekend (as of version 1.5.2) you will be able to sort by last name via the following:

    [userlist meta_key="last_name" orderby="meta_value" order="ASC"]

    In the mean time (the time it takes for me to traverse the Atlantic ocean) you can filter the query via pre_user_query which is your chance to modify the user query, much like pre_get_posts does for post queries.

    function kia_sort_by_last_name( $query ){
    	if(  isset( $query->query_id ) && $query->query_id == 'simple_user_query' ){
    		$query->set( 'meta_key', 'last_name' );
    		$query->set( 'orderby', 'meta_value' );
    		$query->set( 'order', 'ASC' );
    	}
    }
    add_filter( 'pre_user_query', 'kia_sort_by_last_name' );
  3. vicksterm
    Member
    Posted 8 months ago #

    Many thanks!!

  4. helgatheviking
    Member
    Plugin Author

    Posted 8 months ago #

    Update is just being pushed out now.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.