Skip Navigation

[Resolved] Sort by secondary in sorting controls

This support ticket is created 6 years, 7 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.

Our next available supporter will start replying to tickets in about 0.80 hours from now. Thank you for your understanding.

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 4 replies, has 2 voices.

Last updated by markusK-6 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#648908

Hello,

i do not know how i can sort by seondary field in the sorting controls.
All results should always by first sort by "field-wpcf-paket" and secondary sort by customer select.
At the moment whe i change the sorting so the sort by field-wpcf-paket is not set.

hidden link

Please help.

Nice regards
Markus

#649748

Hi, I don't think it's possible to allow Users to control a secondary sorting method in a View's filters, but you may be able to do something like this with the wpv_filter_query and some custom code. We have documentation for this filter and some examples available here:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

You could check the User's selected Query, then manipulate the final Query to insert the Paket order as primary, then the User selection as secondary. It's fairly complex when you have to account for order by post title and/or meta values, but there is a similar example here: https://wordpress.stackexchange.com/questions/65769/multiple-orderby-values-in-wp-query

#651940

Hi Christian,

can you please give me an example how i can set the order by user as secondary sorting and set the primary sorting always to paket?

If it is extra work for you so you can create me an offer for that work.

#652778

The closest example of this type of query I can find is here: https://wordpress.stackexchange.com/questions/65769/multiple-orderby-values-in-wp-query/65772#65772

Here's an example showing how you can modify a query, including the orderby clause, with the wpv_filter_query API:

add_filter( 'wpv_filter_query', 'filter_fieldslug_9876', 10, 3 );
function filter_fieldslug_9876 ( $query, $view_settings, $view_id ) {
  $views = array( 1234 );
  if( in_array( $view_id, $views) ) {
    $args = array(
      'relation' => 'AND',
      array(
        'key' => 'wpcf-fieldslug',
        'value' => 9876,
        'compare' => '=',
        'type' => 'numeric'
      )
    );
    // add these arguments to your meta query
    $query['meta_query'] = isset($query['meta_query']) ? $query['meta_query'] : [];
    $query['meta_query'][] = $args;
    $query['orderby'] = 'wpcf-fieldslug menu-order';
  }

 return $query;
}

I'm happy to help troubleshoot custom code you have written related to our APIs, but we don't write that level of customization for you here in the support forums. If you're interested in getting professional assistance, you may be able to connect with a skilled developer in our Contractors portal: https://toolset.com/contractors

#672364

ok i will contact the contractors for help.
Is there a possibility that this feauture will be implemented in future releases of Toolset?
I think that is an important point the secondary sorting.

Nice regards
Markus