# Filter Posts With or Without a Featured Image

> Adds a "Featured image" dropdown above admin post lists to show only posts that have one or only those that are missing one, which makes fixing gaps quick.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin-filters, featured-image, posts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admin-filter-by-featured-image/

## Code

```php
add_action( 'restrict_manage_posts', function ( $post_type ) {
    if ( ! post_type_supports( $post_type, 'thumbnail' ) ) {
        return;
    }

    $current = isset( $_GET['wpide_thumb'] ) ? sanitize_key( $_GET['wpide_thumb'] ) : '';
    ?>
    <label class="screen-reader-text" for="wpide-thumb-filter">Filter by featured image</label>
    <select name="wpide_thumb" id="wpide-thumb-filter">
        <option value="">Featured image: any</option>
        <option value="with" <?php selected( $current, 'with' ); ?>>With featured image</option>
        <option value="without" <?php selected( $current, 'without' ); ?>>Without featured image</option>
    </select>
    <?php
} );

add_action( 'pre_get_posts', function ( $query ) {
    if ( ! is_admin() || ! $query->is_main_query() || empty( $_GET['wpide_thumb'] ) ) {
        return;
    }

    $compare = 'with' === $_GET['wpide_thumb'] ? 'EXISTS' : 'NOT EXISTS';
    $meta    = is_array( $query->get( 'meta_query' ) ) ? $query->get( 'meta_query' ) : array();
    $meta[]  = array( 'key' => '_thumbnail_id', 'compare' => $compare );
    $query->set( 'meta_query', $meta );
} );
```

## Notes

Works on every post type that supports featured images.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Filter Posts With or Without a Featured Image" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
