How to Flush the Re-write Cache In WordPress

Published by Sam Wilson on

It is common for blog pages to come back with a 404 error, and any further investigations carried out will find that the homepage works correctly. Even if you attempt to view your pages through the ID number there will seem like there are no problems. However, when you try to view them through the ‘Pretty Permalinks’ you will comes across problems. This is no time to panic because it is quite likely that the problem is associated with a rewrite rules cache that is out of date. The difficulty of the issue is dependent on the access you have to your WordPress installation as well as the backend of your website.

Here, we will look at the three ways in which you can flush the WordPress rewrite cache.

Flushing via the Dashboard

WordPress enables the creation of URLs that can be bunched together, but are completely recognisable. They contain posts that are clustered together under archives or categories. Whenever a change is made to these structures, there is an automatic flushing of the cache. In order to do this without making any changes it is a case of pressing the save button.

On the left hand side of the administration dashboard select “Settings” and then select “Permalinks”. At the bottom of the page there is an option to “Save Changes”. Click this.

If you have the ability to access your .htaccess file, it will create an automatic flush of the cache and any required changes will be made. This is the easiest and direct way of flushing the rewrite rules caches, however, if this is not successful then it is possible to do this through the database.

Removing the Cache from the Database

When choosing to go down this road, caution has to be taken because it is recommended that a backup of the entire database is made before any changes are made. One mistake could completely ruin the WordPress installation. However, flushing the rewrite rules using this method is relatively straightforward and only requires the deletion of a value in a single field.

To do this, access your database using your chosen method. Find the database where WordPress belongs and click the SQL tab and then type the following text into the text box

SELECT * FROM  wp_options WHERE  option_name =  ‘rewrite_rules’

Click go, which can be found on the bottom right to carry out the command. This will bring up one row, so click edit. You will now see all of the editable fields within the row, the one you need to look at is the called “option_value” and it contains alphanumeric strings.

Now it is a case of deleting everything that is found within the field before clicking save. Now when you access your WordPress site it will be rebuilt automatically.

Flushing via PHP

It is vital to remember that this option is one that can be extremely resource heavy and is one that you would not want to run automatically each time WordPress is loaded. Therefore, this command should only be attached a fairly rare incidence such as the activation of a plug-in or the de-activation.

The PHP function that flushes the rewrite cache is as follows:

flush_rewrite_rules();

As mentioned previously, it is not wise to include this at the end of your functions. Php file because that would result in it running all of the time. As an alternative, find out whether there is a pre-existing condition before giving it permission to carry it out an action that is deemed as necessary.

These methods of flushing the rewrite cache will ensure that you have the right options available to you should you need to fix your WordPress site when you no longer have access to the pages through the usual permalinks.

Categories: Tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *