How to hide some specific attachments using post meta from media library

I want to hide some attachements with specific meta value from media library. I have hide attachments in list view of me

I want to hide some attachements with specific meta value from media library. I have hide attachments in list view of media library using the below function

add_action( 'load-upload.php' , 'wp_231165_load_media' );


function wp_231165_load_media() {
   add_action('pre_get_posts','wp_231165_hide_media',10,1);
}

function wp_231165_hide_media($query){
    global $pagenow;
    if( 'upload.php' != $pagenow  || !is_admin())
        return;

    if(is_main_query()){

        $query->set( 'meta_query', array(
        'relation' => 'OR',
        array(
            'key' => 'is_view',
            'value' => true,
            'compare' => '!='
        ),
        array(
            'key' => 'is_view',
            'compare' => 'NOT EXISTS'
        ),

    ) );
    }

    return $query;
}

But when I take grid view all files are still there.

I tried using one filter

add_filter( 'ajax_query_attachments_args', function( $args ) {
   $args->set( 'meta_query', array(
    'relation' => 'OR',
    array(
        'key' => 'iskyc',
        'value' => true,
        'compare' => '!='
    ),
    array(
        'key' => 'iskyc',
        'compare' => 'NOT EXISTS'
    ),

) );

   return $args;
} );

but don't know how to set meta query in this filter. Please help

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744746491a4591330.html

相关推荐

  • How to hide some specific attachments using post meta from media library

    I want to hide some attachements with specific meta value from media library. I have hide attachments in list view of me

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信