I am using magic fields and have defined a custom post type called collection
with a field called sort
, where I input a number I would like to sort the custom posts by.
My WP_Query arguments is simply:
'post_type' => 'collection',
'meta_key' => 'sort',
'order_by' => 'meta_value',
'order' => 'ASC'
Which, upon using print_r on the $query result reveals the following mysql statement:
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'collection' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND (wp_postmeta.meta_key = 'sort' ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC LIMIT 0, 10
So I am confused why the generated mysql still contains ORDER BY wp_posts.post_date
when I am explicitly stating it should sort by wp_postmeta.meta_key = 'sort'
and its corresponding meta_value
?