* Tell us what you are trying to do? *
I need to set the secondary sorting option a custom (toolset) field.
The Metakey is: wpcf-business-owner-or-team-member
The slug is: business-owner-or-team-member
Type: Checkbox
So when users view the output on this page: hidden link
The list would sort by 'Post Title' THEN by 'wpcf-business-owner-or-team-member'
Is there any documentation that you are following?
Unable to find any Views documentation 🙁
Is there a similar example that we can see?
Nope 🙁
What is the link to your site?
hidden link
Thanks so much in advance - I'd really appreciate any direction on how to make this work 🙂
Hello,
There isn't such kind of built-in feature within Toolset Views:
1) First, in your screenshot:
https://toolset.com/wp-content/uploads/2021/10/2192547-Sort_By.png
The custom fields are not available in the option "Secondary sorting", you should be able to see this option supports only few fields
2) Second, Toolset custom checkboxes field stores value in serialized array format, you can not use it to sort view's results, in your same screenshot, option "Ordering", you will not find the checkboxes field "business-owner-or-team-member" too.
So my opinion is "not to go".
Thanks so much Luo - apprecate your help! I had realised that there is no option, natively, to use custome fields as a second sort condition.
I've changed the custom feild to a drop down (rather than a checkbox) - i didn't realise the way these values are stored affects the way they are used.
I've set the view now to:
1) Sort by the custom field 'Business Owner or Team Member
2) Post Title (alpha)
But I really do need to reverse these.
Would there be any way to customize the Javascript to do this?
It is possible with custom codes, you can use wpv_filter_query to change the orderby parameter, for example:
Add below codes into your theme file"functions.php":
add_filter( 'wpv_filter_query', function($query, $setting, $view_id){
if(in_array($view_id,array(2970))){
$query['meta_key'] = 'wpcf-' . 'business-owner-or-team-member';
$query['orderby'] = array('title' => 'ASC', 'meta_value_num' => 'ASC');
}
return $query;
}, 999, 3);
Please replace 2970 with your post view's ID, replace business-owner-or-team-member with custom field slug of 'Business Owner or Team Member'
More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
My issue is resolved now. Thank you!