Skip Navigation

[Resolved] Sorting by two custom fields

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to apply a secondary sorting on a custom field.

Solution:
Currently, Toolset views cannot use a custom field as a secondary order. The selection is limited to default fields, or randomly, instead of custom fields. Check this screenshot for the available secondary sorting options http://prntscr.com/tnbj4o

But we can work around it with custom code, by hooking into the query filters. Check the solution in this ticket https://toolset.com/forums/topic/sort-by-2-custom-fields/

Relevant Documentation:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://codex.wordpress.org/Class_Reference/WP_Query

This support ticket is created 4 years, 4 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by fatios 4 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#1715701

Hello to all the team,

I know this topic has come up a few times but all the threads I find on the forum about this are a couple of years old.
I have a custom post type with two custom fields: a date custom field and a selection custom field (which corresponds to time slots).
I would like to create a view that displays my customs posts chronologically: First by date then by time slot.
Is there a solution now to do this?

Thank you for your support

#1716135

Hello and thank you for contacting the Toolset support.

Currently, Toolset views cannot use a custom field as a secondary order. The selection is limited to default fields, or randomly, instead of custom fields. Check this screenshot for the available secondary sorting options hidden link

But we can work around it with custom code, by hooking into the query filters. Check the solution in this ticket https://toolset.com/forums/topic/sort-by-2-custom-fields/

For more reading, check these articles:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://codex.wordpress.org/Class_Reference/WP_Query

I hope this helps. Let me know if you have any questions.

#1718651

Hello Jamal,
I have followed your advice and it seems to be working fine! Thanks a lot for your help, my issue is resolved now.