Filter images from media library by guid meta field
I am using the ajax_query_attachments_args filter attempting to remove certain images from the wordpress media library. They are all in a separate folder within the uploads directory called speakers-bureau which is why I am trying the guid meta query.
Here is my code
add_filter('ajax_query_attachments_args', 'remove_speakers_bureau_images');
function remove_speakers_bureau_images($query)
{
$query['meta_query'] = [
[
'key' = 'guid',
'value' = 'speakers-bureau',
'compare' = 'NOT LIKE',
]
];
return $query;
}
The idea being to only show images that are not in that folder, but this returns nothign in the media folder library.
I Found code for this here on stackexchange. Any help would be awesome!
EDIT: Thanks for the response @TomJNowell. I thought the images that show up in the media library was a loop of the posts? I can query the guid in phpMyAdmin and get the results I want. For now I am querying by author with an array of accepted IDs and the current users ID. This keeps out the one off images loaded up that go into this speakers-bureau folder.
add_filter('ajax_query_attachments_args', 'remove_speakers_bureau_images');
function remove_speakers_bureau_images($query)
{
$current_user_id = get_current_user_id();
$allowed_users = array( $current_user_id,
1,2,6,20,3421,11021,16372,17890,17891,20239,27034,27739,28058,34270,36844,44537,60162,68352,
75068,77660,94386,101763,104623,114529,127857,134328,140253,177524,189351,198849,221723,242161,251734,
253145);
$query['author__in'] = $allowed_users;
return $query;
}
Topic meta-query media-library post-meta ajax guids Wordpress
Category Web