admin管理员组文章数量:1122846
I haven't set a limit to the number of revisions, which makes some of my post have more than 20 revisions, so how to delete these revisions?
By the way, I am using WPMU and have many blogs, so how to delete WordPress revisions for all my blogs?
I haven't set a limit to the number of revisions, which makes some of my post have more than 20 revisions, so how to delete these revisions?
By the way, I am using WPMU and have many blogs, so how to delete WordPress revisions for all my blogs?
Share Improve this question edited Oct 16, 2012 at 19:20 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Oct 16, 2012 at 4:00 hugemeowhugemeow 2552 silver badges10 bronze badges7 Answers
Reset to default 11This is a much safer query to use and will remove related entries from the postmeta and term_relationship, unlike deathlocks query in his answer.
Change the {id} to the id of each blog posts table. You can combine this query to run all the post tables at once, but try this on one table first. I've used it many times on single WP installs.
DELETE a,b,c
FROM wp_{id}_posts a
LEFT JOIN wp_{id}_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_{id}_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision'
After you run it, optimize the database in phpmyadmin.
And add this line near the top of wp-config.php to prevent future revisions:
define('WP_POST_REVISIONS', 0);
or save one revision:
define('WP_POST_REVISIONS', 1);
There is also a plugin, WP Optimize that can help you do this
From the website:
WP-Optimize is a WordPress 2.9++ database cleanup and optimization tool. It doesn't require PhpMyAdmin to optimize your database tables.
It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.
To delete all of your Wordpress revisions, you could use this query:
DELETE FROM wp_posts WHERE post_type = "revision";
You could also add this code to your theme's functions.php
file:
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 3);
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', false);
This code checks if WP_POST_REVISIONS
limit has been set in wp-config.php
, If it hasn’t then it passes a parameter to the function that limits post revisions. In the example above, posts are limited to 3 revisions.
This is a good solution when building themes for people who dont know how to (or dont want to) add code.
Taken from wp-functions.com
You can use the WP Sweep plugin to clean post revisions. After activating the plugin, go to Tools » Sweep to clean up your WordPress database.
Use wp_delete_post_revision is the safest way:
global $wpdb;
$query = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'revision'");
if ( $query ) {
foreach ( $query as $id ) {
wp_delete_post_revision( intval( $id ) );
}
}
Thanks for the answer, markratledge. Something in the syntax regarding the {id} did not work for me. I changed {id} to 4009, one of my post ids, but no success. I found a solution on https://dev-notes.eu/2017/11/manage-and-safely-delete-revisions-in-wordpress/
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';
That worked fine.
本文标签: multisiteHow to delete post revisions
版权声明:本文标题:multisite - How to delete post revisions? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311218a1934659.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论