Hi Pascal,
Thanks for writing back and for sharing these details.
I've checked the page that you referred to and noticed that the custom function to order the results, based on two custom fields is working as expected.
( screenshot: removed )
The same can be confirmed on a new example page, with better visibility:
( screenshot: removed )
Based on what you've shared in your last message, you don't just need to order the results, but in fact, you need to group them together too, based on the "Regions".
( this is different from what was discussed in the other ticket: https://toolset.com/forums/topic/expanding-sort-function-users/ )
To achieve what you're planning, you'll need two views:
1. A parent view to show "Example view to show all user regions":
This view will need to be set to show a list of users, ordered by the "Region" user field )
2. A child view to show "Example view to show user companies based on a region":
This nested view will also show the list of users, but it will have a query filter to show only the users, which have the "Province" field value same as the one passed as the shortcode attribute from the parent view.
( ref: https://toolset.com/documentation/user-guides/passing-arguments-to-views/ )
Important notes:
a). The code snippet to use "wpv_filter_user_query" has been commented out since it is not needed.
b). To control the order of the Region names, you can arrange them in the "Provincie" field's settings, since it is a "Select" type field.
( screenshot: removed )
3. Note that a custom script will be needed to remove the duplicate Region entries from the parent view "Example view to show all user regions"
( screenshot: removed )
jQuery(document).ready(function(){
var seenGenre = {};
// loop over regions
jQuery('.provincie-wrap').each(function(index,item) {
var txt = jQuery(item).text();
var $h3 = jQuery(item).closest('h3');
// if region has been seen, remove it
if (seenGenre[txt] || seenGenre[txt + ', ']){
jQuery(item).remove();
}else{
seenGenre[txt] = true;
}
});
});
I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar