Problem: I would like to order a View by one custom field (primary) and another custom field (secondary).
Solution: Add the following code to your functions.php file to modify the Query:
add_filter( 'wpv_filter_query', 'order_by_two_custom_fields',199,3 ); function order_by_two_custom_fields( $query_args, $views_settings, $view_id) { $view_ids = array( 12345 ); $args = array(); if (in_array($view_id, $view_ids)){ $args = array( 'meta_query' => array( 'relation' => 'AND', 'function-clause' => array( 'key' => 'wpcf-function', 'compare' => 'EXISTS', 'type' => 'NUMERIC' ), 'begin-clause' => array( 'key' => 'wpcf-begin_date', 'compare' => 'EXISTS', 'type' => 'NUMERIC' ) ), 'orderby' => array( 'function-clause' => 'ASC', 'begin-clause' => 'ASC' ) ); } return array_merge($query_args, $args); }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_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 3 replies, has 2 voices.
Last updated by 6 years, 7 months ago.
Assisted by: Christian Cox.