Skip Navigation

[Resolved] Secodary Ordner with meta field

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 5 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#1223171

Hello!

i have "Events" with a date and a Number field ("reihenfolge") = sort order with numbers from 1-11

now i want the view to order with date and then with "reihenfolge"

i have tried this:
// SECODARY ORDNER EVENTS
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 == 2754 ){

$meta_query = array();
$meta_query[] = array('key' => 'wpcf-datum');
$meta_query[] = array('key' => 'wpcf-reihenfolge');
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';
}

Here you can see the view (the little white numbers in the Corder of the Images are the number field "Reihenfolge"

hidden link

#1223354

You can already sort by more than one ordering argument in the native Views Ordering options, but only the primary supports custom fields.
To allow custom fields ordering also on the secondary options you'll have to suggest this to the Product Management here:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

We can assist only limitedly in enhancing Views with Custom code.
https://toolset.com/toolset-support-policy/

However, this is a widely requested feature and we elaborated often on it, with custom code samples.
I think the best example is this https://toolset.com/forums/topic/need-help-with-a-secondary-orderby-on-a-view/#post-415478

Please try that out, and let me know if you need an explanation on its usage, I think however Nigels' explanation is well documented.