Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author webbistro

    (@webbistro)

    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

    Thread Starter iltdevunit

    (@iltdevunit)

    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');
    Plugin Author webbistro

    (@webbistro)

    Hi @iltdevunit,

    Thanks for posting your solution. It may be helpful for someone else.

    Nadia

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide term from media library’ is closed to new replies.