Skip Navigation

[Resolved] incorrect behavior of "order by" custom field

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.


This topic contains 2 replies, has 2 voices.

Last updated by Brad 4 years, 11 months ago.

Assigned support staff: Luo Yang.


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.


Luo Yang

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Dear Brad,

This is expected result, Views query posts database using wordpress class WP_Query, according to wordpress document:
'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.


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