Home » What is WordPress Guide » WordPress Database » Deleting Expired WordPress Transients & Post Revisions – Nexcess

Deleting Expired WordPress Transients & Post Revisions – Nexcess

WordPress management and WordPress maintenance are important aspects of overall site health. Deleting expired WordPress transients/post revisions is vital!

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

Deleting Expired WordPress Transients & Post Revisions



WordPress management and WordPress maintenance are important aspects of overall site health. Deleting expired WordPress transients/post revisions is vital!

How to Delete Expired Transients & Post Revisions Using WP-CLI

Backup Early, Backup Often

It’s always a good idea to have a recent backup…

Before making any change to the settings for your WordPress site, it’s always a good idea to have a recent backupIf your WordPress site or WooCommerce portal is running on one of our managed WordPress hosting plans, you know one aspect of WordPress management that we handle for you is automatic daily backups of your content and data. However, since the most recent daily backup may have been performed hours and hours ago, please create a manual backup using your managed WordPress portal or using the WordPress Command Line Interface (WP-CLI) from inside the terminal.

Using WP-CLI to Perform a Manual Backup

Since we’ll be in a terminal session today using WP-CLI already, let’s create a quick backup from the command line.

First, after you’ve opened a Secure Shell (SSH) connection to your server, let’s make sure our working directory is the directory of our WordPress installation. In this example, our WordPress site is located in the default site document root, public_html.

[wpclitesting@host ~]$ cd public_html/

[wpclitesting@host public_html]$ ls
Error_log           wp-config-sample.php    wp-login.php

Index.php           wp-config.php           wp-mail.php

Readme.html         wp-content              wp-settings.php

Wp-activate.php     wp-cron.php             wp-signup.php

Wp-admin            wp-includes             wp-trackback.php

wp-blog-header.php  wp-links-opml.php       xmlrpc.php


We can see the WordPress configuration files, so we know we’re in the right place.

Next, we’ll run a quick backup of our WordPress database:

[wpclitesting@host public_html]$ wp db export ../wp-cli-testing-20220114.sql
Success: Exported to 
‘../wp-cli-testing-20220114.sql’.


WordPress Transients — Why Should We Remove Expired Transients

WordPress intends for transients to be used for short-term caching of data inside the WordPress database. However, WordPress does not automatically delete expired transients. Instead, the creator of an expired WordPress transient (almost always a plugin) is expected to handle that aspect of WordPress maintenance. But some plugins that use transients do not always remove their respective transients after they expire. Over the span of months and years, these expired-but-not-deleted transients living inside the wp_options table of the database can begin to slow things down and impede site performance. For this reason, we should remove expired transients to improve WordPress site performance.

WordPress Transients — A Closer Look

Let’s make sure our version of WordPress supports transients.

[wpclitesting@host public_html]$ wp core version
5.1.6


In this example, we’re


In this example, we’re running with WordPress Version 5.1.6, first released in mid-2020. Because WordPress has supported transients since WordPress Version 2.8, our version is recent enough to have the supported transients included.

Though recent enough to have transients, our version in this example is slightly outdated and should be updated to a more recent version. See our blog post, WordPress Updates: How To Install an Update Safely, for a good guide on updating core WordPress.

And here are the transients in our example WordPress site:

[wpclitesting@host public_html]$ wp transient list

+———————————————+———————————————-+————+

| name                                        | value                                         | expiration |

+———————————————+———————————————-+————+

| jetpack_akismet_key_is_valid                | valid                                         | 1641913553 |

| jetpack_idc_allowed                         | 1                                             | 1641866392 | *

| jetpack_plugin_api_action_links_refresh     | 1641532868                                    | 1641845488 | *

| jetpack_sync_constants_await                | 1641536958.2617                               | 1641913553 |

| jetpack_sync_last_checked_queue_state_sync  | a:2:{i:0;i:0;i:1;i:0;}                        | 1641912144 |

| slimstat_visit_id                           | 1299                                          | false      |  

| update_plugins                              | O:8:”stdClass”:1:{s:12:”last_checked”;i:0;}   | false      |

| update_themes                               | O:8:”stdClass”:1:{s:12:”last_checked”;i:0;}   | false      |

| twentyseventeen_categories                  | 2                                             | false      |

| wpcom_social_media_icons_widget::is_active  | 0                                             | 1641835570 | *

+———————————————+———————————————-+————+


As mentioned earlier, WordPress transients are not automatically deleted after expiration, so your list of transients may have more entries than this example list. However, from our example list above, you can see transients with expiration dates (the ones with a number) and ones without expiration dates (the ones labeled ‘false’).

The expiration value is time in seconds since midnight, January 1, 1970. For example, the transient named jetpack_akismet_key_is_valid has an expiration of 1641913553, which correlates to 2022-Jan-11 09:05:53am.

If you’re having caching or performance issues related to a specific transient, you can delete a specific transient by referencing the name:

[wpclitesting@host public_html]$ wp transient delete jetpack_akismet_key_is_valid
Success: Transient deleted.

Rather than remove each expired transient individually by name, we can tell WordPress to delete every expired transient quickly.

[wpclitesting@host public_html]$ wp transient delete –expired
Success: 3 expired transients deleted from the database.


Ready to get started?

Get the fastest, most secure WordPress.org hosting on the market.

Additional resources

What is managed WordPress hosting? →

Get details and decide if managed WordPress hosting is right for you.

Must-have web development plugins to create WordPress websites at scale →

Explore the best web development plugins to enhance functionality, improve performance, and streamline your WordPress site.

A complete guide to WordPress shortcodes →

Shortcodes make life easier. Learn how to get started!