Problem: I would like to sort a View by two custom fields.
Solution:
Add custom code to your functions.php file:
add_filter('wpv_filter_query', 'add_custom_fields_to_view_query', 199, 3); function add_custom_fields_to_view_query($query_args, $view_settings, $view_id ) { $view_ids = array( 4497 ); if( in_array( $view_id, $view_ids)) { $query_args['meta_query'] = array( 'relation' => 'AND', 'year_clause' => array( 'key' => 'wpcf-ce-year', 'compare' => 'EXISTS', 'type' => 'NUMERIC', ), 'month_clause' => array( 'key' => 'wpcf-current-entries-month', 'compare' => 'EXISTS', 'type' => 'NUMERIC', ), ); $query_args['orderby'] = array( 'year_clause' => 'ASC', 'month_clause' => 'ASC', ); } return $query_args; }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://codex.wordpress.org/Class_Reference/WP_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 |
---|---|---|---|---|---|---|
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 14 replies, has 2 voices.
Last updated by 5 years, 11 months ago.
Assisted by: Christian Cox.