I have a get_posts query that doesn't seem to be sorting correctly.
$args = array(
'post_type' => array(),
'order_by' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(),
);
There are later lines that populate the post_type
and meta_query
arrays, but I don't believe they are required to illustrate the problem. I am telling this to sort by title ascending. Yet, when the query returns, I get an order like this:
There doesn't seem to be a rhyme or reason to this. I have checked the database, and there are no special characters. I've even run the select query
SELECT *
FROM `prestige_posts`
WHERE post_type = 'workers'
ORDER BY post_title
LIMIT 0 , 30
manually and gotten the exact result I expect. Other locations in the code have almost exactly the same query and work correctly. So why isn't this returning properly?
I.E. An example from one function up in the same file that does return correctly:
$args = array(
'post_type' => $postType,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => -1,
'post_parent' => $entry['id'],
);
$lastposts = get_posts($args);
I'm just an idiot.
The key is orderby
, I was using order_by
. That was the issue. Just took me hours to spot it.