In WordPress, I created a new WP_Query with a few simple args to get a custom post type. However, no results came back. I could look at the query by checking WP_Query’s request property. The query, when run in mysql returned the desired rows. So what was happening to these rows?
WP_Query’s posts property holds all the posts that will be returned. Looking into wp-includes/query.php, it turned out that I didn’t have read permissions. I was trying to show private posts. The user needed ‘read_post’ and ‘read_private_posts’ permissions (‘post’ can be replaced with your custom capability).
On a side note, tax_query does not work in the args if you are retrieving a single post object. What determines this? It depends on what args you send WP_Query. If you send it args like ‘name’, ‘p’, ‘page_id’, and some other parameters it will mark it as is_single and it will not perform tax_query! This took me a while to find.