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
评论列表(0条)