I have a custom dropdown field in my media uploader which saves to the posts meta. Now I'm trying to get all images with a specific value with a meta_query. The variable $author is exactly the value that is saved in the postmeta in MySQL.

$rd_args = array(
    'meta_query' => array(
            'key' => 'post_slider_author',
            'value' => $author

$rd_query = new WP_Query( $rd_args );

$mh_posts = $rd_query->posts;

As you can see in the screenshot there is a value assigned to the meta post_slider_author and '1139' is also the correct ID. Unfortunately the query stays empty.

enter image description here

Additional: I tried to disable all plugins but it had no effect. Normal queries work just fine.

  • The code here looks correct which means it's likely not something shown here that is causing an issue. You'll have to narrow down your issue through debugging conventions to get to the root cause. You may want to try logging the SQL via $rd_query->request
    – Howdy_McGee
    Aug 18, 2021 at 18:12
  • 1
    Is post_slider_author saved to the post or to the attachment? Keep in mind that by default WP_Query only queries posts. You need to set post_type if you want another post type. Aug 19, 2021 at 12:54
  • @JacobPeattie post_slider_author is saved to the attachement but I also changed post_type to attachment -> no effekt
    – M. H.
    Aug 20, 2021 at 18:28
  • Can you var_dump( $author ) right before the $rd_args to make sure it's not blank? That'd be my first guess, is that it's checking for something that isn't there. So we need to make sure that whatever $author passes to the $rd_args is the correct thing in the correct format. Aug 23, 2021 at 19:47

1 Answer 1


I change it to get_posts() instead of new WP_Query and it works just fine. No idea what's the problem with the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.