Hello @iltdevunit,
Please give me more details about your task. What does this mean “hide all images”? Where? From whom? On front-end? From non-admins? And so on…
Nadia
Hi Nadia,
Sorry, I should have given more information.
I have a media category called ‘avatar’, with an ID of 177. I wanted to hide these from appearing in the media library (upload.php).
I managed to do it by adding this code to functions.php
function hide_media_categories($query) {
global $pagenow;
if( ( 'upload.php' != $pagenow ) || !$query->is_admin ){
return $query;
}
$tax_query = array(
array(
'taxonomy' => 'media_category',
'field' => 'id',
'terms' => array(177),
'operator' => 'NOT IN'
)
);
$query->set( 'tax_query', $tax_query );
}
add_filter('pre_get_posts', 'hide_media_categories');
Hi @iltdevunit,
Thanks for posting your solution. It may be helpful for someone else.
Nadia