Sorting problem with ‘query_posts’ funcion in wordpress. Sort by custom field not working

order_by doesn’t take a name of the field, it takes type of order. Which for custom numeric field will be orderby=meta_value_num. But actual field used is taken from meta_key and you are already using it for filtering. See Orderby Parameters.

So you can’t pull this of this easily at moment, not without filtering and modifying resulting SQL query. Upcoming WP 3.1 will have much more improved and flexible querying support for custom fields and it will likely be easier than.

Leave a Comment