# Transients Viewer Under Tools

> Adds a Tools > Transients screen listing the cached transients stored in the database with their size and expiry time, and lets administrators delete a single one to force a refresh.

- Type: PHP
- Runs: Admin only
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: transients, caching, debugging
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/debug-transients-viewer/

## Code

```php
add_action( 'admin_menu', function () {
    add_management_page( 'Transients', 'Transients', 'manage_options', 'wpide-transients', function () {
        global $wpdb;

        if ( isset( $_POST['wpide_delete_transient'] ) && current_user_can( 'manage_options' ) && check_admin_referer( 'wpide_transients' ) ) {
            $name = sanitize_text_field( wp_unslash( $_POST['wpide_delete_transient'] ) );
            delete_transient( $name );
            echo '<div class="notice notice-success"><p>' . esc_html( sprintf( 'Deleted transient %s.', $name ) ) . '</p></div>';
        }

        $rows = $wpdb->get_results(
            "SELECT o.option_name, LENGTH(o.option_value) AS bytes, t.option_value AS expires
            FROM {$wpdb->options} o
            LEFT JOIN {$wpdb->options} t ON t.option_name = CONCAT('_transient_timeout_', SUBSTRING(o.option_name, 12))
            WHERE o.option_name LIKE '\\_transient\\_%' AND o.option_name NOT LIKE '\\_transient\\_timeout\\_%'
            ORDER BY bytes DESC LIMIT 200"
        );

        echo '<div class="wrap"><h1>Transients</h1>';
        if ( ! $rows ) {
            echo '<p>No transients are stored in the database.</p></div>';
            return;
        }
        echo '<form method="post"><table class="widefat striped"><thead><tr><th>Name</th><th>Size</th><th>Expires</th><th></th></tr></thead><tbody>';
        wp_nonce_field( 'wpide_transients' );
        foreach ( $rows as $row ) {
            $name    = substr( $row->option_name, strlen( '_transient_' ) );
            $expires = $row->expires ? ( $row->expires < time() ? 'expired' : 'in ' . human_time_diff( (int) $row->expires ) ) : 'never';
            printf(
                '<tr><td><code>%1$s</code></td><td>%2$s</td><td>%3$s</td><td><button class="button button-small" name="wpide_delete_transient" value="%1$s">Delete</button></td></tr>',
                esc_attr( $name ),
                esc_html( size_format( (int) $row->bytes ) ),
                esc_html( $expires )
            );
        }
        echo '</tbody></table></form></div>';
    } );
} );
```

## Notes

Sites with Redis or Memcached keep transients in the object cache, so the list will be short or empty there.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Transients Viewer Under Tools" 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/
