Skip Navigation

[Resolved] Custom Date Field Not Sorting

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

Problem: I have a View that should be ordered by the value of a custom date field, but it does not seem to be ordered correctly.

Solution: Be sure no other query filters are interfering with the sort order settings in Views. Use the Views debug panel if necessary to check the query criteria.

This support ticket is created 6 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
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 8 replies, has 3 voices.

Last updated by Sammut 6 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#952274

We have a custom field called "Cruise Start Date" of the field type "date".

The view is set to display search results sorted by "Cruise Start Date" in ascending order and yet the search results are not sorting in this manner. Yet, when we set this search up they were. Can you offer any direction or guidance? Thank you.

#952775

I cannot replicate the issue.

I made a short video here of what I tried:
hidden link

I see you use several other plugins, have you tried without them?
There may be a conflict introduced.

Or, I miss a step or detail.
Please let me know if the Video's content corresponds to what you try.

If it does as well not help to re-save or eventually duplicate and apply a new view, after all other steps above, please let us know

#952869

Thank you. Yes, these are the steps we used to create our view. The view has been live for months. Oddly, it stopped working with the last Toolset update.

#953153

Hi, please try the following troubleshooting steps first:
- Temporarily activate the default Twenty Seventeen theme, deactivate all plugins except Types and Views, and test the View again.
- If the problem is resolved, reactivate your theme and plugins one by one until the problem returns.
- If the problem is not resolved, please take a screenshot of the View editor in wp-admin so I can see the Query Filter configurations.

Let me know what you find out and we can go from there.

#953598
Screenshot 2018-07-23_08-32-35.png
Screenshot 2018-07-23_08-32-14.png
Screenshot 2018-07-23_08-31-10.png

Hi!

Yes, thank you we already ran through theme and plugin conflicts.

I attached a screenshot and very much appreciated your help!

#953778

Okay thanks for the additional information. I don't see anything in this View's setup that would indicate a problem. Can you show me how the View is inserted on this page? For instance, it could be inserted with a shortcode like this that overrides the order-by configurations:

[wpv-view name="your-view-slug" orderby="title"]

If you do not see the "orderby" attribute, try to turn off caching for this View by adding the cached="off" attribute like this:

[wpv-view name="your-view-slug" cached="off"]

Check the results to see if it makes any difference.

If neither seems to be the issue in your case, please turn on debugging temporarily by going to Toolset > Settings > Frontend Content > Debug mode. Reload the page where this View is displayed, and you should see a popup appear. If you do not, check your browser's popup settings and allow popups for this page. Reload to see the popup. Use the "Show" buttons to toggle open all sections of this View debug popup, then copy + paste the full contents here for me to review. After that, you can turn off debug mode again.

#953780

Thank you, yes, we do have inserted as:

[wpv-view name="cruise-search" cached="off"]

Thank you, here you go!

Page info
Current page hidden link
Total memory used 5.7851MB
Render time 1.59
Total MySQL queries 123
CPU usage 1.57%
Elements info
- Cruise Search (Cruise Itineraries ordered by Field - wpcf-cruise-start-date, ascending)

ID 16855
Name Cruise Search (Edit)
Kind of element View
Render time 0.28654
Memory used 0.6862MB
Summary Cruise Itineraries ordered by Field - wpcf-cruise-start-date, ascending
Query args Hide
Basic query arguments
Array
(
[post_type] => Array
(
[0] => cruise-itinerary
)

[paged] => 1
[suppress_filters] =>
[ignore_sticky_posts] => 1
)
MySQL query Hide
SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND wp_posts.ID NOT IN (17241) AND (
wp_term_relationships.term_taxonomy_id IN (369)
) AND (
wp_postmeta.meta_key = 'wpcf-cruise-start-date'
) AND wp_posts.post_type = 'cruise-itinerary' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) GROUP BY wp_posts.ID ORDER BY wp_posts.menu_order, wp_postmeta.meta_value+0 ASC
... truncated by admin for readability ...

#953864

The post queries indicate the problem is the posts are being ordered primarily by menu_order, and secondarily by the custom field date:

SELECT wp_posts.* FROM wp_posts ... ORDER BY wp_posts.menu_order, wp_postmeta.meta_value+0 ASC

That's not normal, and I would usually suspect a theme or plugin of injecting this additional ORDER BY clause. However, you said that you tested and saw the same results without your theme and other plugins active. So I'll need to take a closer look here and see what's going on. I would like to create a clone of your site so I can run some tests locally without disturbing the live site. I can install the Duplicator Pro plugin to create that clone and get started testing. If that's okay, please provide login credentials in the private reply fields here.

#953896

OH Yikes!!!! I did not look at that query hard enough and we have a custom function that we use for custom sorting. Ughhhh. Thanks. Issue solved!!