Skip Navigation

[Resolved] Order posts by custom date field

This support ticket is created 6 years, 11 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 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#596333

Hi there, and thank you for your time.

First of all, please look at this page: hidden link

The posts here are created by members submitting a Cred form which allows them to enter details in lots of fields which are assigned to the custom post type "courses". All fields, post types and forms are created in Toolset.

It works beautifully to this point.

As you will see however on that pate, there is one issue: the posts are displayed out of date order. They should show the next event first in the list, then with events getting later as you scroll down the list.

Can you tell me how to order these events in date order (the field is called "start-date-for-event") and importantly how that is achieved direct in the taxonomy-coursetypes-one-day-course.php template file, rather than in the Views module as we have created the site in template files.

I hope you can help.

Many thanks and best wishes,
Andrew.

#596366

Hi, if you are not using Views to display your data, then sorting your posts must be handled in your custom code. Here is the documentation for the "order" and "orderby" parameters:
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Orderby a meta value is described in the docs. Types fields are saved in the postmeta table as "wpcf-" + slug, so if your field slug is "start-date-for-event" then the meta key for that field is "wpcf-start-date-for-event".