Hi, @beachmat
It is possible to filter the media library in WordPress to display only featured images. To do this, you can use the parse_query
hook in combination with the meta_query
parameter to filter the media library to display only items that are marked as featured images.
Here’s an example of how you could use this hook to filter the media library to display only featured images:
add_action( 'parse_query', 'filter_media_library' );
function filter_media_library( $query ) {
// Make sure we're in the admin and on the correct screen
if ( is_admin() && isset( $_GET['post_type'] ) && 'attachment' == $_GET['post_type'] ) {
// Check if the 'featured_image' query var is set
if ( isset( $_GET['featured_image'] ) && '1' == $_GET['featured_image'] ) {
// Set the meta_query to only show items that are marked as featured images
$query->query_vars['meta_query'] = array(
array(
'key' => '_thumbnail_id',
'value' => '',
'compare' => '!='
)
);
}
}
}
To use this code, you can add it to your theme’sfunctions.php
file or create a custom plugin.
Then, to filter the media library to display only featured images, you can add the featured_image=1
query variable to the URL of the media library page. For example: https://yoursite.com/wp-admin/upload.php?featured_image=1
I hope this helps! Let me know if you have any questions.
Thank you.