I'm having trouble getting my custom ordering to work. I'm trying to order a custom post type by a custom field called
feature_order which is a numeric field (created with Advanced Custom Fields plugin).
Here is the code:
$args = array( 'post_type' => 'attorneys', 'posts_per_page' => -1, 'meta_key' => 'feature_order', 'orderby' => 'meta_value_num', 'order' => 'ASC' ); $query = new WP_Query( $args );
This has no effect on the actual order. The
feature_order field was created correctly, and properly stores values, so that's not the issue.
Here's the SQL produced by when I use
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_postmeta.meta_key = 'feature_order' ) AND wp_posts.post_type = 'attorneys' 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
The problem is the presence of
wp_posts.menu_order in the
ORDER_BY clause. When I execute the query directly on the database without this, I get the expected result.
How do I get WP_Query to stop ordering by
Alernatively, how can I instantiate a WP_Query object with an SQL string?
Thanks in advance for your help!