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(
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.
Additional: I tried to disable all plugins but it had no effect. Normal queries work just fine.
$rd_query->request
post_slider_author
saved to the post or to the attachment? Keep in mind that by defaultWP_Query
only queries posts. You need to setpost_type
if you want another post type.post_slider_author
is saved to the attachement but I also changed post_type toattachment
-> no effektvar_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.