• Hi there,

    I am trying to sort a [users] shortcode by a custom field that has been added to the users named ‘orderpos’.

    I’ve attempted to use orderby, key, order etc in the shortcode but this always defaults to sorting by the username/display name (not sure which, both are the same for all users)

    The code I am using follows

    [users role="core" orderby="meta_value_num" key="orderpos" order="ASC"]
    <h5>[user] [user orderpos]</h5>
    [/users]

    Does ‘orderby’ only work with posts and not users? Is there any way to sort users in this way?

    Thanks for your help!

    Gregor

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I looked into this. Ordering by user field value wasn’t well-supported, so I improved it in the latest update.

    If the field is a numerical value, you can do this:

    [users role="core" orderby="field_num" field="orderpos" order="ASC"]

    The shortcode uses the native function get_users() to generate the user list – and interestingly, orderby=”meta_value_num” was not supported, unlike posts. So it was necessary to manually sort the list to achieve this feature.

    Thread Starter Gregor

    (@vaderw)

    Fantastic support, very quick turnaround, users are now sorting correctly ascending but changing to ‘order=DESC’ doesn’t take effect?

    Many thanks

    Gregor

    Plugin Author Eliot Akira

    (@miyarakira)

    Ah, yes, I hadn’t thought of that. OK, now descending order is supported. It’s ascending by default.

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