Problem:
How to order a Users View by a custom user field
Solution:
Changing the order by option to a non-standard setting not included in the GUI dropdown requires a custom code snippet using the wpv_filter_user_query filter:
add_filter( 'wpv_filter_user_query', 'custom_orderby_func', 100, 3 ); function custom_orderby_func( $query_args, $view_settings, $view_id ) { if ( $view_id == 123 ) { $query_args['meta_key'] = 'wpcf-company'; $query_args['orderby'] = 'meta_value'; $query_args['order'] = 'ASC'; } return $query_args; }
Change the meta_key as required.
Relevant Documentation:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_user_query/
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 |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+01:00)
This topic contains 4 replies, has 2 voices.
Last updated by gaborG 7 years, 3 months ago.
Assigned support staff: Nigel.