# Remember Your Filters in Admin Lists

> Brings back the status, category, author, search and sorting you last used when you return to the Posts, Pages or Media list, instead of starting from "All" every time.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin-lists, filters, productivity
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admin-remember-list-filters/

## Code

```php
// Query arguments worth remembering.
$wpide_remembered_args = array( 'post_status', 'cat', 'category_name', 'author', 'm', 's', 'orderby', 'order', 'tag', 'post_format', 'mode', 'attachment-filter' );

$wpide_remember_filters = function () use ( $wpide_remembered_args ) {
    global $pagenow;

    $post_type = isset( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : ( 'upload.php' === $pagenow ? 'attachment' : 'post' );
    $screen    = $pagenow . ':' . $post_type;
    $saved     = (array) get_user_meta( get_current_user_id(), 'wpide_list_filters', true );
    $current   = array_intersect_key( wp_unslash( $_GET ), array_flip( $wpide_remembered_args ) );

    if ( $current ) {
        $saved[ $screen ] = array_map( 'sanitize_text_field', $current );
        update_user_meta( get_current_user_id(), 'wpide_list_filters', $saved );
        return;
    }

    // A plain visit restores the last filters, unless "All" was clicked from the list itself.
    $from_list = wp_get_referer() && false !== strpos( wp_get_referer(), $pagenow );
    if ( ! empty( $saved[ $screen ] ) && ! $from_list && empty( $_GET['paged'] ) ) {
        $args = $saved[ $screen ];
        if ( 'attachment' !== $post_type && 'post' !== $post_type ) {
            $args['post_type'] = $post_type;
        }
        wp_safe_redirect( add_query_arg( array_map( 'rawurlencode', $args ), admin_url( $pagenow ) ) );
        exit;
    }

    if ( $from_list && isset( $saved[ $screen ] ) ) {
        unset( $saved[ $screen ] );
        update_user_meta( get_current_user_id(), 'wpide_list_filters', $saved );
    }
};

add_action( 'load-edit.php', $wpide_remember_filters );
add_action( 'load-upload.php', $wpide_remember_filters );
```

## Notes

Click the post type menu link twice, or "All", to clear the remembered filters; stored per user and per screen.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remember Your Filters in Admin Lists" 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/
