Skip Navigation

[Resolved] How to sort a View by standard field then custom field

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

Problem:
A View includes a custom field filter, and the results should be ordered by first a standard WP field then by the custom field.

Solution:
That is currently not supported. You can include custom fields in sorting, but only for the primary sort order, not the secondary.

This support ticket is created 6 years, 5 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by neilH-3 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#915035
types.jpg

Tell us what you are trying to do?
create a View loop that displays CPTs by a custom field date, not one of the default sorting options

Is there any documentation that you are following?
KB

Is there a similar example that we can see?
Look here: hidden link

What is the link to your site?
hidden link

General -

As you can see, I have created a View for the CPT - International Biodynamics Course. I need to add a secondary sorting criteria. I have it set to sort by title / ascending. But the courses are also listed by date, so I need to add the course date into the sorting shortcode so that courses are listed first by title, then by date.

the courses dates are a custom post type.

#915170

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Neil

Views lets you add primary and secondary fields for ordering, but there is a limitation that you can use custom fields for the primary order condition, but not the second, where you can only use standard WP fields.

So you could order by custom date field then by title, but not by title then custom date field.

So what you are trying to do right now is simply not supported.

If it were imperative that you order your posts in such a way the only solution would be for you to use the wpv_filter_query_post_process hook to re-order the posts yourself.

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process

An array of the View results can be manipulated using that hook.

#916064

Thanks Nigel. Too bad my need here isn't available in Views. As an FYI - Advanced Custom Fields plugin does allow for the secondary sorting requirement... maybe this is something you might consider adding into your roadmap?