[HELP] Filter Media Query Loop by meta_key value

Hello guys! I know this will be a lil advanced and tricky stuff but I trust on you.

Well, i have a slider that is populates using a Query Loop , Type Media. But i got a lil problem now, i have 2 gallery fields of SCF. One called pictures, and other called amenities, well, slider is loading all pictures in the post, pictures+amenities images. but i would like to filter the images and show pictures gallery images only! (not amenities). I have tried using meta keys but when i set for example meta_key=pictures and EXISTS, slider just hide all pictures in it! T.T omg i can’t figure out how to solve this! By the way amenities pictures are loaded into a gallery block (works fine)

How can i set query loop media juist for showing images in pictures custom field??? T.T

Heeelp me please!

Hi . Try meta_key=_pictures
But I’m not sure that it works because we search by images and there is no such meta key.

Enable Query editor (PHP) and apply the code

$post_id = get_the_ID();
$pictures_ids = get_post_meta($post_id, '_pictures', true);

if (!empty($pictures_ids) && is_array($pictures_ids)) {

    $query_args = [
        'post_type'      => 'attachment', 
        'post_status'    => 'inherit',   
        'post__in'       => $pictures_ids, 
        'posts_per_page' => -1,
        'orderby'        => 'post__in',
    ];

    return $query_args;
} else {
    return [];
}
1 Like

MAN!!! You ARE a Genius!! I just change _pictures to pictures and it worked fine!