Problem:
The issue here is that the user wanted to sort her view by multiple custom fields.
Solution:
This can be done by using the custom hook below.
add_filter('wpv_filter_query', 'add_custom_fields_to_view_query', 99, 3); function add_custom_fields_to_view_query($query_args, $view_settings, $view_id ) { if ( $view_id == 16257 ){ $meta_query = array(); $meta_query[] = array('key' => 'acf_directory_sort_order'); $meta_query[] = array('key' => 'acf_shipping_city'); if ( !isset($query_args['meta_query']) ){ $query_args['meta_query'] = array(); } $query_args['meta_query'] = array_merge($meta_query, $query_args['meta_query']); add_filter('posts_orderby', 'custom_order'); } return $query_args; } function custom_order($orderby) { global $wpdb; return $wpdb->postmeta.'.meta_value ASC, mt1.meta_value ASC'; }
Where you simply need to chance the names of the custom fields in the code that you want to sort by.
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.
Our next available supporter will start replying to tickets in about 2.45 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
This topic contains 25 replies, has 2 voices.
Last updated by 6 years, 8 months ago.
Assisted by: Shane.