1
votes

So I have this query

$args = array(
    'post_type' => 'course', // custom post type
    'post_status'   => 'publish',
    'posts_per_page' => -1,
    'orderby'   => 'title'
);

$courses = new WP_Query($args);

This gives me what I want, but the orderby statement is being ignored. When I dump the $courses->request I get this

'SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'course' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.menu_order ASC '

It is defaulting the orderby to menu_order instead of title. What's going on here?

2
you need to pass both parameters 'orderby'=> 'title', 'order' => 'ASC' ?Noman
I've tried with and without that. I think the default is 'ASC' anywayJohn Halsey

2 Answers

1
votes

I was facing the same issue and I solved it using 'post_title' instead of 'title'.

$args = array(
    'post_type' => 'course', // custom post type
    'post_status'   => 'publish',
    'posts_per_page' => -1,
    'orderby'   => 'post_title' // change here
);

$courses = new WP_Query($args);
0
votes

check whether you have used parse_query or pre_get_posts hook somewhere in the website

add_action( 'pre_get_posts', 'function_name' );
add_filter( 'parse_query',  'function_name' );