Skip Navigation

[Resolved] Woocommerce Events Products are not sorting correctly by WooCommerceEventsDate

This support ticket is created 5 years, 3 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 Nigel 5 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1294953

I am trying to: Sort a View by WooCommerceEventsDate (field provided by WooCommerce Events plugin

Link to a page where the issue can be seen: hidden link

I expected to see: Events sorted by date (ascending or descending)

Instead, I got: Events are NOT sorted correctly regardless of asc or desc.

#1294973
#1294997

It seems to store it as a string: when I modify the view to simply spit out the value of the field I get "23 July 2019" and "30 July 2019". I created a funtion to swap out the values so that the front end displays "July 23 2019"

If the view is set to Desc I get:
July 30
July 23
August 15

Ascending gives me:
August 15
July 23
July 30

So it appears the sorting is alphabetical no matter what I use?

#1295009

Nigel
Supporter

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

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

You didn't seem to be online to chat, so I converted this to a forum thread.

I took a look at your site, and I can see that the date is stored by the plugin in the format "15 August 2019".

Your View to display these products ordered by the WooCommerceEventsDate field is set to sort it as a native custom field, effectively a string, and the alternative is to sort it as a number.

The underlying options available with WordPress (the WP_Query class which Views uses to query the database for data) only has these options for ordering, treating the field as a string or a number.

I hope you'll appreciate that sorting dates such as 19 September 2019 and 2 August 2019 isn't going to work in either case.

This is one of the reasons Types date fields are stored as timestamps (numbers).

The only option I see is for you to write a custom code snippet using the wpv_filter_query_post_process API filter that takes the results of the View and then re-orders them to your needs with PHP before outputting them: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process