60Web60

Flushing cache and rewrite rules with WP-CLI

WP-CLI2 min read·

WordPress stores cached data to serve pages faster. Sometimes this cache becomes stale, showing old content after you have made changes. Flushing the cache forces WordPress to rebuild it. Similarly, rewrite rules control how WordPress URLs work. Flushing them fixes broken page URLs and 404 errors on pages that should exist.

Command reference

CommandWhat it does
wp cache flushClears the WordPress object cache
wp rewrite flushRegenerates WordPress permalink (URL) rules
wp rewrite flush --hardForces a full regeneration of rewrite rules, including writing to .htaccess
wp transient delete --allDeletes all transients (temporary cached data stored in the database)
wp option get rewrite_rulesShows the current rewrite rules stored in the database

When to flush cache

  • After updating a plugin or theme
  • After changing a setting that affects page content
  • After running wp search-replace
  • If pages are showing old content
  • If you have just installed a caching plugin

When to flush rewrite rules

  • After changing the permalink structure
  • After adding a new custom post type
  • After a plugin install that adds new URL patterns
  • If you are getting 404 errors on posts or pages that exist

Need help?

If you have questions about cache and rewrite rules, visit our support page or email hello@smarthost.ie.

Frequently asked questions

Will flushing the cache affect my visitors?

Briefly. The first request after a cache flush will be slightly slower as WordPress rebuilds the cache. Subsequent requests return to normal speed.

Why am I getting 404 errors on pages that exist?

This is almost always a rewrite rules issue. Run wp rewrite flush and the problem should resolve immediately.

How is wp cache flush different from wp transient delete --all?

wp cache flush clears the WordPress object cache (stored in memory or a persistent cache layer). wp transient delete --all removes transients stored in the database. Transients are often created by plugins to store temporary data.

Last updated: 25 March 2026