Skip Navigation

[Closed] Secondary sorting a view by toolset custom field

This support ticket is created 3 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
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 Christian Cox 3 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#2028789

I have a view in wich i display posts with two different values of the same custom field (categoria-relacionada). In the query filter of the view i'm using a Custom Field Filter with this value: "Select items with field: Categoría relacionada is a string between contemporaneas, noveles". Also, there are user-controlled filters on the page with this view.

I need to sort the results by my custom field "categoria-relacionada" and then by date/price, but if i use the custom field as a primary sort it appears on the front and the user can control that (wich i don't want to), so i think i need to use the custom field for secondary sorting the results, how can i accomplish that?

#2028955

Hello, let me make sure I understand what you want to accomplish. It sounds like you are you saying you want to sort primarily by the categoria-relacionada field, and then apply a secondary sort by some other criteria like date or price when the same categori-relacionada value exists in multiple posts. You would have to choose either date or price in this case, since there is no tertiary sorting method. There is only primary and secondary sorting. If multiple posts have the same primary sorting value, the secondary sorting value is applied.

It also sounds like you are concerned about sorting controls appearing on the front-end of the custom search View. Do you want any sorting controls at all to appear?

How is this View built - are you using the legacy View editor or the Blocks editor to create the View?

#2028987

Hi Christian, thanks for your reply.

What i want is to let the users control the date/price order but not the categoria-relacionada field order. That's why i tried to use it as a secondary sorting. I do not need a tertiary sorting option. I want to be able to sort by date/price and also by my custom field so category A appears before category B. If i sort by date, the results must be category A newest to oldest, then category B newest to oldest.

The view was created with the legacy version. If you need access to the site let me know and i provide you with credentials.

#2029743

If i sort by date, the results must be category A newest to oldest, then category B newest to oldest
Okay so that implies that the primary sorting algorithm should always be the categoria-relacionada field, but you want the front-end sorting feature to choose the secondary sorting algorithm (either date or price). Unfortunately Views front-end sorting will always choose the primary sorting algorithm, so there isn't a built-in feature that will allow you to set the primary sorting algorithm in the backend and allow Users to choose the secondary sorting algorithm on the front-end. That would be somewhat confusing, if the User chooses to sort by Price but the results are returned in some other order, like sorted by the categoria-relacionada field first. The results would appear to be sorted incorrectly if the User chooses Price in that scenario. I can't think of an example to share where the sorting works exactly like you have described, since the front-end sorting controls will only set the primary sort order. You might be able to use custom programming to achieve something like this, but I don't have any similar examples to share. I can direct you to our PHP filter APIs that can be used to programmatically adjust filters and sort order:
https://toolset.com/documentation/programmer-reference/views-filters/
We have the wpv_filter_query API and the wpv_filter_query_post_process API, which can be used to manipulate results programmatically.

The topic ‘[Closed] Secondary sorting a view by toolset custom field’ is closed to new replies.