WordPress文章ID不连续和关闭自动保存关闭解决办法
第一步:找到并打开 wp-config.php 文件,在 $table_prefix = 'wp_';前面添加如下代码:
- define('AUTOSAVE_INTERVAL', false );
- define('WP_POST_REVISIONS', false);
第二步:找到并打开 wp-adminpost-new.php 和 wp-adminpost.php 这两个文件,将其 “wp_enqueue_script(‘autosave’);” 注释或删除掉,特别要注意一下,post.php和post-new.php这两个文件在很多文件夹里面都有,注意路径,前往不要改错了.
实例代码如下:
//wp_enqueue_script('autosave');
第三步:找到并打开 wp-adminincludespost.php 文件,找到如下代码:
- if ( $create_in_db ) {
-
- $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
- foreach ( (array) $old_posts as $delete )
- wp_delete_post( $delete, true );
- $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
- $post = get_post( $post_id );
- if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
- set_post_format( $post, get_option( 'default_post_format' ) );
- } else {
替换成如下代码:
- if ( $create_in_db ) {
- global $current_user;
- $post = $wpdb->get_row( "SELECT * FROM $wpdb->posts WHERE post_status = 'auto-draft' AND post_type = '$post_type' AND post_author = $current_user->ID ORDER BY ID ASC LIMIT 1" );
- if ( !$post ) {
- $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
- $post = get_post( $post_id );
- }
- if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
- set_post_format( $post, get_option( 'default_post_format' ) );
- } else {
注意:修改完成后系统已无自动保存功能,需要手工保存草稿.