最新wordpress4.7.4文章ID不连续的解决方法

经本站测试感觉,是一个简单而实用的有效方法,适合于wordpress3.0-4.7.4的版本,可以完美解决wordpress文章ID不连续的问题。
说方法是直接把代码扔进主题functions.php中就可以了


function keep_id_continuous(){
global $wpdb;
$lastID = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' OR post_status = 'draft' OR post_status = 'private' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ORDER BY ID DESC LIMIT 1");
$wpdb->query("DELETE FROM $wpdb->posts WHERE ( post_status = 'auto-draft' OR ( post_status = 'inherit' AND post_type = 'revision' ) ) AND ID > $lastID");
$wpdb->query("ALTER TABLE $wpdb->posts AUTO_INCREMENT = 1");
}
// 将函数钩在新建文章、上传媒体和自定义菜单之前。
add_filter( 'load-post-new.php', 'keep_id_continuous' );
add_filter( 'load-media-new.php', 'keep_id_continuous' );
add_filter( 'load-nav-menus.php', 'keep_id_continuous' );
// 禁用自动保存,所以编辑长文章前请注意手动保存。
add_action( 'admin_print_scripts', create_function( '$a', "wp_deregister_script('autosave');" ) );
// 禁用修订版本
add_action('post_updated','wp_save_post_revision',10,1);

Continue reading ‘最新wordpress4.7.4文章ID不连续的解决方法’ »