• In the media library, I’d like to see only featured images, but there doesn’t seem to be a filter for it. I also can’t find any plug-in that adds it. Ok, I could add a plug-in that lets you add folders, and then put them in one, but that feels like quite a bit of hassle for what seems such an obvious thing. Perhaps I’m missing something – is there a way to do it?
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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_queryhook in combination with the meta_queryparameter 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.

    Thread Starter beachmat

    (@beachmat)

    Thanks, but that code isn’t working for me. When I add the parameter to the URL, it makes no difference to the number of images listed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Media Library featured filter’ is closed to new replies.