[wordpress主题]WordPress文章ID不连续和关闭自动保存关闭解决办法

时间:2017-12-26  来源:WordPress  阅读:

第一步:找到并打开 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 ) {

 代码如下

if ( $create_in_db ) {

    // Cleanup old auto-drafts more than 7 days old

    $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 ); // Force delete

    $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 {

注意:修改完成后系统已无自动保存功能,需要手工保存草稿

[wordpress主题]WordPress文章ID不连续和关闭自动保存关闭解决办法

http://m.bbyears.com/wangyezhizuo/38045.html

推荐访问:wordpress教程 wordpress大学
相关阅读 猜你喜欢
本类排行 本类最新