WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. StormCloud
    Member
    Posted 1 year 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.

    Thanks

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

  2. helgatheviking
    Member
    Plugin Author

    Posted 1 year 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:
    http://codex.wordpress.org/Class_Reference/WP_User_Query#Order_.26_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){
       $args['orderby']='post_count';
       return $args;
    }
    add_filter('sul_user_query_args','filter_simple_user_listing_args');

    It looks like you can query by meta fields:
    http://codex.wordpress.org/Class_Reference/WP_User_Query#Custom_Field_Parameters

    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
    Member
    Posted 1 year ago #

    How to show only users who have posts?

  4. helgatheviking
    Member
    Plugin Author

    Posted 1 year 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.

    http://codex.wordpress.org/Class_Reference/WP_User_Query

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

  5. Francesco
    Member
    Posted 9 months ago #

    What if I want to order by LASTNAME the users?

  6. helgatheviking
    Member
    Plugin Author

    Posted 9 months 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
    Member
    Plugin Author

    Posted 9 months ago #

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

    http://stackoverflow.com/questions/12392847/wordpress-user-query-order-by-meta-value

    http://wordpress.stackexchange.com/questions/30977/list-users-by-last-name-in-wp-user-query

    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
    Member
    Posted 9 months ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.