I have the following custom query written for a page- $menu_loop = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => 50, 'post_parent' => 616, 'order_by' => 'post_title', 'order' => 'ASC' ) ); while ($menu_loop->have_posts()) : $menu_loop->the_post();

The problem is, when the content is output to the page, it is NOT in alphabetical order by post_title. This has really been mystifying me because if I manually query the DB with- SELECT * FROM wp_2_posts WHERE post_type = 'page' AND post_parent = 616 ORDER BY post_title ASC

then the results are returned correctly. Further, I print_r($menu_loop) and one of the array entries is the actual query sent to the DB and it is wrong and showing- [request] => SELECT SQL_CALC_FOUND_ROWS wp_2_posts.* FROM wp_2_posts WHERE 1=1 AND wp_2_posts.post_parent = 616 AND wp_2_posts.post_type = 'page' AND (wp_2_posts.post_status = 'publish') ORDER BY wp_2_posts.post_date ASC LIMIT 0, 50

which if you look you'll see the ORDER BY statement is sorting by the post date, not the post title.

What am I doing wrong here?


Your sorting parameter should be: 'orderby' => 'title'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.