Can’t search posts using WP_QUERY inside AJAX Function

Below you will find some things you might want to consider regarding post types. But one note up front:

Every WP_Query is done for the current user. If you do not see what you expect, try it with a logged in admin user first. This way you can easily check if the problem is a capability issue.

About the post status you seem to be querying from the DB:

  • private: This post status is only available for Administrators who are logged in.
  • publish: Double check if you got these in the results. They are there by default. You don’t even need to add them.
  • privatised: Is this a custom post status? If so, make sure you don’t have set exclude_from_search set. Also note, that custom status are not supported as per now.
  • draft: iirc they are only visible if you have the edit_others_posts capability available for the role that the searching user has.
  • inherit: This will include attachments and revisions. Note that this might be a capability issue as well.
  • future: Same as above.

Make sure to test the “problem” you are facing via a mini-plugin in some admin screen first to check if it’s an admin UI/ frontend problem. Constants are different, etc. If it works there, you have either missing constants or a user role that is not capable of viewing what you want to see in the queried results.

Make sure to read @TomJNowells answers about taxonomies vs other things like post types. TL;DR: You will find out that in some cases you do not want a taxonomy … or want nothing than a taxonomy. Also it’s not that hard to register a custom taxonomy with custom capability handling and maybe a custom meta box. This way you can navigate around any problems that are related to the Tumblr-Clone Feature Post Status, that was never finished and never properly thought trough and never was fully implemented. It might be much easier to get there by doing what you want to do without any restrictions from an obsolete and left over feature.

Links to developer.wordpress.org: