Simple User Listing
[resolved] Order By Custom Field (8 posts)

  1. StormCloud
    Posted 2 years ago #

    Hey i had a similar version of this that i'd adapted from the same smashing magazine article, but i've merged mine with your much neater coding structure.. nicely done.

    I have one thing i can't achieve yet.. is there a way for me to order by a custom field?

    I have custom fields from s2member in my userlist, that works fine, but i'd like to order the list by one of the custom fields.



  2. helgatheviking
    Plugin Author

    Posted 2 years ago #

    Sorry for the delay. I always forget to subscribe to my plugin's forums.

    You can order the WP_User_Query with the following orderby parameters:

    I don't really know how you'd do it by a custom field. You might have to write your own where and orderby clauses. You can change my plugin's query args via filter

    $args = apply_filters( 'sul_user_query_args', array_merge( $args1, $args2 ) );

    So for example, you could order by post_count

    function filter_simple_user_listing_args($args){
       return $args;

    It looks like you can query by meta fields:

    But I couldn't tell you how to make them play together. Maybe you can try setting the orderby parameter to metakey. If you figure it out, let me know. Also, let me know if you'd like me to add some parameters to the shortcode.

  3. Nisadoji
    Posted 2 years ago #

    How to show only users who have posts?

  4. helgatheviking
    Plugin Author

    Posted 2 years ago #

    @Nisadoji - I don't know. It's up to you to figure out how to use the WP_User_Query class the way you want.


    Let me know if you find a solution, I can document it for others.

  5. Francesco
    Posted 2 years ago #

    What if I want to order by LASTNAME the users?

  6. helgatheviking
    Plugin Author

    Posted 2 years ago #

    I would also recommend you read the docu for WP_User_Query: http://codex.wordpress.org/Class_Reference/WP_User_Query

    However, I don't believe there is an easy way to order by user meta. You'd probably have to do something a little complicated.

  7. helgatheviking
    Plugin Author

    Posted 1 year ago #

    Ordering by a meta is definitely messy, but these answers might help:



    As of version 1.4 of SUL you can pass custom query_id parameters which will then allow you to specifically target that query at the pre_get_users hook.

  8. Francesco
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Simple User Listing
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.