I have the following wp_query:
$args = array(
'post_type' => 'news',
'orderby' => 'meta_key',
'order' => 'ASC',
'meta_key'=>'custom_author_name',
'post_per_page'=>-1
);
$query = new WP_Query($args);
echo $query->found_posts;
echo = 10 results because there are only 10 news
posts with a meta_key = custom_author_name
. But there are hundreds of news
posts that don’t have a post_meta row with that specific meta_key. Please notice, that there is no meta_query involved. No meta_value is assigned, because I am only trying to sort the posts by meta_key, and not filter by meta_value.
Shouldn’t orderby select all posts? and just order them?
If so why is the result filtered? If the meta_key is not found, why not just use an empty string, or a match all?
If not, why not?
If I enter a meta_key to every news post (even if it’s an empty string) then I get the expected result. But that seems like a whole lot of table rows that don’t need to be there.