We can add the Featured option as a fake mime-type with:
add_filter( 'media_view_settings', function( $settings )
{
$settings['mimeTypes']['wpsefeaturedimage'] = 'Featured';
return $settings;
});
It will show up like this:
Then we can use the posts_where
filter and check for our fake mime type:
/**
* Filter for featured images in the media library popup
*/
add_action( 'pre_get_posts', function( \WP_Query $q )
{
if( 'wpsefeaturedimage' === $q->get( 'post_mime_type' ) )
{
// Remove the fake mime type
$q->set( 'post_mime_type', '' );
// Mark this query as featured filtered
$q->set( 'wpse_filter_featured', true );
add_filter( 'posts_where', function ( $where, \WP_Query $q )
{
if( $q->get( 'wpse_filter_featured' ) )
{
global $wpdb;
// Add 'featured images' restriction to the SQL query
$where .= " AND {$wpdb->posts}.ID IN
( SELECT DISTINCT m.meta_value FROM {$wpdb->postmeta} m
WHERE m.meta_key = '_thumbnail_id'
) ";
}
return $where;
}, 10, 2 );
}
}, 1 );
We can probably adjust this further.