I have encountered this problem many times. This problem only happen when I programmatically create/edit posts. They could be customs post or even Wordpress' default post. The symptoms could be:
post_status
is set to 'any'
. Curiously when I set post_status
to published
it works.This is a self-answered question. I encountered this problem several times before and always forget its cause. And searches hint to possibilities that many others are stuck without solution too.
TL;DR;: It's publish
, not published
.
The cause of this problem is because I when programmatically create new posts, I set its post_status
to published
. Common reason for the confusion is when you approve a post programmatically, switching post status from pending
to published
because it seem logical.
The reason those posts are showing in neither queries nor admin dashboard is because WP_Query
's post_status => 'any'
doesn't actually query for 'any' post status as we expect, but any registered post status. Since wordpress had no prior knowledge of the post status published
, they're simply ignored by the queries.
Now here's to hope I don't forget what I wrote today again next year.