Skip Navigation

[Résolu] incorrect behavior of "order by" custom field

This support ticket is created Il y a 8 années et 5 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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: Asia/Hong_Kong (GMT+08:00)

Marqué : 

This topic contains 2 réponses, has 2 voix.

Last updated by Brad Il y a 8 années et 5 mois.

Assisted by: Luo Yang.

Auteur
Publications
#341260
orderbyexample.JPG

I found an error that would be unlikely to manifest except in the unusual case that a custom field has been created but not yet populated with a value in any post.

When specifying such a custom field as the "order by" field in a View, the result is an incorrect "No posts found" error. The "order by" should not affect the query result, only the ordering of the result.

As soon as I populated a post with a value in the "order by" field (Numeric Rank in my example attached) the query produced the desired result.

#341298

Dear Brad,

This is expected result, Views query posts database using wordpress class WP_Query, according to wordpress document:
http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
'meta_value' - Note that a 'meta_key=keyname' must also be present in the query.
So if you sort view by a custom field, all result should have a value in the custom field, or it will return empty items.

#343807

Thanks for setting me straight. Allowing a sortation key to change a query result seems wrong, but I guess that's up to WordPress.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.