Skip Navigation

[Resolved] View sorting for non custom field (roles) content

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a View of Users I would like to sort by role.

Solution: The standard WordPress User Query isn't sortable by role so this is unfortunately a limitation of the WordPress system. We do offer some PHP APIs that you can use to add your own custom sorting.

Relevant Documentation:
https://codex.wordpress.org/Class_Reference/WP_User_Query#Order_.26_Orderby_Parameters
https://toolset.com/documentation/user-guides/allowing-visitors-to-sort-the-front-end-results/
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_post_query

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by grahamA 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1311287
Sorting.jpg

Tell us what you are trying to do?
I have user type view with multiple columns plus roles displayed. I need to sort by this column
Is there any documentation that you are following?

Is there a similar example that we can see?
I have implemented your code to add roles to my view successfully however I need to sort this column. Please see attached image.
Can you tell me what shortcode needs to go into the wpv-heading shortcode.
What is the link to your site?

#1311435

Hi, the standard WordPress User Query isn't sortable by role so this is unfortunately a limitation of the WordPress system: https://codex.wordpress.org/Class_Reference/WP_User_Query#Order_.26_Orderby_Parameters
https://toolset.com/documentation/user-guides/allowing-visitors-to-sort-the-front-end-results/

Since our system uses that query for searches, sorting by role isn't supported from wp-admin. However, we do offer a couple of PHP APIs that may be helpful here if you are comfortable writing custom code. You can manipulate the results of the View, including the sort order, after the query is run, with this API:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_post_query
Click "+More" to see an example of using that API.

An example showing sorting of Users by role in PHP, which may be helpful:
http://bitsandbabble.com/2014/12/make-wp_user_query-sort-by-role/

#1311471

My issue is resolved now by being signposted to external solution. Thank you!