Queries posts by a postmeta key/value pair directly from the master database.

This is not intended for front-end usage. This purpose of this function is to avoid race conditions that could appear while the caches are primed. A good scenario where this could be used is to ensure published posts are not syndicated multiple times by checking if a post with a certain meta value already exists.


Name Type Description
$meta_key string Post meta key to query
$meta_value string Post meta value to check for
$post_type string Optional; post_type of the post to query. Defaults to 'post'.
$post_stati array Optional; array of the post_stati that are supposed to be included. Defaults to: publish, draft, pending, private.
$limit integer Optional. Amount of possible posts to receive; not more than 10. Default is 1.

Return Value

array|WP_Error: Array with post objects or a WP_Error

Ready to get started?

Drop us a note.

No matter where you are in the planning process, we’re happy to help, and we’re actual humans here on the other side of the form. 👋 We’re here to discuss your challenges and plans, evaluate your existing resources or a potential partner, or even make some initial recommendations. And, of course, we’re here to help any time you’re in the market for some robust WordPress awesomeness.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.