How to clean up WordPress revisions
Set limiting the maximum number of revisions: by adding define('WP_POST_REVISIONS', 50); to the wp-config.php file; or use define('AUTOSAVE_INTERVAL', false); to turn off the auto-save function; 2. Manually delete old revision records: Execute the SQL command DELETE a, b, c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision'; Clean up existing revision data, pay attention to replacing table prefixes and backing up the database in advance; 3. Use plug-ins to batch management: Recommend plug-ins such as WP Optimize, Revisionary and Better Delete Revision to provide a visual operation interface to clean up revision records easily and safely; 4. Regular maintenance suggestions: It is recommended to perform regular cleaning operations every month, combining cache and database optimization to monitor database growth trends to avoid performance problems.
Revisions that are automatically saved by WordPress do take up a lot of database space, especially long-term sites. If you want to clean up these redundant data, the method is actually quite straightforward. The key is how to choose tools and operation methods.
1. Set limits on the maximum number of revisions
WordPress does not limit the number of article revisions by default, but you can add code in the wp-config.php
file to control the maximum number of revisions retained. For example, only the last 50 revisions are retained:
define('WP_POST_REVISIONS', 50);
This prevents too many new revisions from happening in the future. If you just want to turn off the autosave function (not fully recommended), you can also use:
define('AUTOSAVE_INTERVAL', false);
However, doing so may affect the editing experience, after all, automatic saving is still useful.
2. Manually delete old revision records
If you have accumulated a lot of revisions, you can clean it up directly through database operations. The most common way is to use SQL commands:
DELETE a, b, c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';
This statement deletes all records of type revision and their associated data. Note that replace wp_
as your own table prefix. Be sure to back up the database before execution to avoid mistaken deletion.
3. Use plug-ins to batch management
For those who are not familiar with database operations, using plug-ins is safer and more convenient. Common ones are:
- WP Optimize : Provides a visual interface, clean up revisions, spam comments, drafts, etc. with one click.
- Revisionary : Not only clean up, but also manage which roles can create revisions.
- Better Delete Revision : Focus on more thoroughly deleting revision records, including metadata and associations.
After installation, you usually just need to enter the settings page, check the content that needs to be cleaned, and then click "Clean".
4. Regular maintenance recommendations
Cleaning it once is not enough, it is best to establish a regular maintenance mechanism. for example:
- Run SQL cleaning or plug-in cleaning manually once a month;
- Cooperate with cache cleaning and database optimization;
- Monitor the growth trend of database size and deal with abnormalities in a timely manner.
Although these small actions are simple, if ignored, it may cause the website to slow down or even make mistakes over time.
Basically these are the methods, you can choose the right method according to your technical level.
The above is the detailed content of How to clean up WordPress revisions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

There are three ways to exclude specific categories in WordPress: use query_posts(), use the pre_get_posts hook, or use the plug-in. First, use query_posts() to directly modify the main loop query in the template file, such as query_posts(array('category__not_in'=>array(3,5))), which is suitable for temporary adjustment but may affect paging; second, it is safer to add functions in functions.php through the pre_get_posts hook. For example, excluding the specified classification ID when judging the home page main loop, it will not affect other page logic; finally, WPCate can be used

To clear WordPress cache, you must first confirm the cache method before operating. 1. When using the cache plug-in, log in to the background to find the "Clear Cache" button provided by the plug-in (such as "DeleteCache" or "PurgeAll") and click to confirm the clearing. Some plug-ins support clearing separately according to the page; 2. In the absence of the plug-in, enter the cache directory under wp-content through FTP or file manager to delete the cache file. Note that the path may change depending on the host environment; 3. When controlling the browser cache, press Ctrl F5 (Windows) or Cmd Shift R (Mac) to force refresh the page, or clear the browser history and cache data, or use incognito mode to view the latest inside.

To migrate WordPress single site to multi-site mode, follow the following steps: 1. Add define('WP_ALLOW_MULTISITE',true); enable multi-site function; 2. Select subdomain or subdirectory mode according to needs; 3. Enter the "Network Installation" interface to fill in information and modify the configuration files and .htaccess rules as prompts; 4. After logging in to the background again, check whether the multi-site management interface is normal; 5. Manually activate the themes and plug-ins of each site and test compatibility; 6. Set permissions and security measures to ensure that the super administrator's permissions are controlled; 7. If you need to open registration, you should enable the corresponding options and limit the risk of spam sites. The entire process needs to be operated with caution

get_template_part is a practical function used to reuse code blocks in WordPress theme development. It reduces duplicate code and improves maintainability by loading specified template files. Its basic usage is get_template_part($slug,$name), where $slug is a required parameter to represent the basic template name, and $name is an optional variant name. For example, get_template_part('content') loads content.php, and get_template_part('content','single') preferentially loads content-single.php, if not present, fallback

To realize the display of custom user fields on forums, CMS or user management platforms, the following steps must be followed: 1. Confirm whether the platform supports custom user fields. For example, WordPress can be implemented through plug-ins, Discourse through background settings, and Django through custom models; 2. Add fields and configure display permissions, such as setting field types and visibility in WordPress to ensure that privacy data is only authorized to view by users; 3. Call field values in front-end templates, such as using PHP function get_user_meta() or Django template syntax {{user.profile.city}}; 4. Test the field display effect, verify the access permissions of different roles, and the mobile terminal

Installing WordPress mainly includes the following steps: 1. Prepare the host, FTP login information and FTP client that supports PHP and MySQL; 2. Download and unzip the program package from wordpress.org to ensure that the wp-config-sample.php file is included; 3. Create a database in the host control panel, and create a configuration file wp-config.php with wp-config-sample.php to fill in the correct database information; 4. Use FTP or file manager to upload all WordPress files to the website root directory; 5. Access the domain name in the browser and enter the installation wizard, fill in the site title and administrator account information to complete the installation; 6. Install

To make the website or application comment area cleaner, automatic management should be combined with the program. The specific methods include: 1. Set a keyword blacklist to filter sensitive content, which is suitable for the basic stage but is easily bypassed; 2. Use AI models to identify improper content, understand semantics and improve accuracy; 3. Build a manual review mechanism for user reporting to make up for automation blind spots and enhance user trust. Only by combining these three and dynamic adjustments can we effectively improve the quality of comments.

There are three ways to protect the WordPress backend: 1. Use .htpasswd and .htaccess to add server-layer passwords. By creating encrypted credential files and configuring access control, you cannot enter even if you know the login address and account number; 2. Change the default login address and use plug-ins such as WPSHideLogin to customize the login URL to reduce the risk of being automated attacks; 3. In combination with the IP whitelist restricting access sources, set to allow only specific IPs to access wp-login.php in the server configuration to prevent login attempts at unauthorized locations.
