已启用对现有自定义帖子类型的修订,不能使用WordPress

时间:2018-09-29 作者:Thomas

我正在尝试为现有自定义帖子类型启用修订。因为帖子类型大约在2年前就已经创建了,所以我在帖子类型是register的地方添加了revisionssupports 大堆

之前我的代码是:

   $labels = array(
    \'name\' => \'Products\',
    \'singular_name\' => \'Product\',
    \'all_items\' => \'All Products\',      
    \'add_new\' => \'Add New\',
    \'add_new_item\' => \'Add New Product\',
    \'edit_item\' => \'Edit Products\',
    \'new_item\' => \'New Product\',
    \'view_item\' => \'View Product\',
    \'search_items\' => \'Search Products\',
    \'not_found\' =>  \'No Prducsts Found\',
    \'not_found_in_trash\' => \'No Products in Trash\', 
    \'parent_item_colon\' => \'\'
  );
  $supports = array(
    \'title\',
    \'custom-fields\',
    \'editor\',
    \'thumbnail\'
  );
  $args = array(
    \'labels\' => $labels,
    \'public\' => true,
    \'menu_position\' => 5,
    \'rewrite\' => array( \'slug\' => \'products\' ),
    \'has_archive\' => true,
    \'supports\' => $supports 
  ); 
  register_post_type(\'products\', $args);
现在看起来:

   $labels = array(
    \'name\' => \'Products\',
    \'singular_name\' => \'Product\',
    \'all_items\' => \'All Products\',      
    \'add_new\' => \'Add New\',
    \'add_new_item\' => \'Add New Product\',
    \'edit_item\' => \'Edit Products\',
    \'new_item\' => \'New Product\',
    \'view_item\' => \'View Product\',
    \'search_items\' => \'Search Products\',
    \'not_found\' =>  \'No Prducsts Found\',
    \'not_found_in_trash\' => \'No Products in Trash\', 
    \'parent_item_colon\' => \'\'
  );
  $supports = array(
    \'title\',
    \'custom-fields\',
    \'editor\',
    \'thumbnail\',
    \'revisions\'
  );
  $args = array(
    \'labels\' => $labels,
    \'public\' => true,
    \'menu_position\' => 5,
    \'rewrite\' => array( \'slug\' => \'products\' ),
    \'has_archive\' => true,
    \'supports\' => $supports 
  ); 
  register_post_type(\'products\', $args);
此代码未启用自定义帖子类型中的修订。

然后我找到了另一个代码,我把它添加到了我的主题函数中。php:

function add_revisions_custom_post()
{
    add_post_type_support( \'products\', \'revisions\' );
}
add_action(\'init\',\'add_revisions_custom_post\');
这个也不起作用。

有人能建议我如何启用修订吗?

提前谢谢。

EDIT:这是我的wp配置。php文件。

<?php
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information
 * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don\'t have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define(\'WP_MEMORY_LIMIT\', \'64MB\');

define(\'DB_NAME\', \'MYDBNAME\');

/** MySQL database username */
define(\'DB_USER\', \'MYDBUSER\');

/** MySQL database password */
define(\'DB_PASSWORD\', \'MYDBPASSWORD\');

/** MySQL hostname */
define(\'DB_HOST\', \'localhost\');

/** Database Charset to use in creating database tables. */
define(\'DB_CHARSET\', \'utf8\');

/** The Database Collate type. Don\'t change this if in doubt. */
define(\'DB_COLLATE\', \'\');

define(\'WP_MEMORY_LIMIT\', \'64MB\');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define(\'AUTH_KEY\',         \'c7ypbekexsfbt4wiucppwewene93cbtcfhf6xgpggepycabhildsoyqpre5iv3wi\');
define(\'SECURE_AUTH_KEY\',  \'ujjxufvylpndsj0qeuwa90gxawj3cgaqnyusrdbmujmb08r37pnyreorpcyxqouu\');
define(\'LOGGED_IN_KEY\',    \'vwlhlmenthgrq9g5jcocihz4ndldhrpegmcp6qyb3rfmjvxjejbacv1zharaexlp\');
define(\'NONCE_KEY\',        \'qhnyqgmqckh3ylasveugagqlvifiuqajl6s9e7ulfrxepdxh2mewr8qhdinua8o2\');
define(\'AUTH_SALT\',        \'rlb723gcatjvkfrd3jscmvdjio3kx9apm5yie9e4ibxktnnlukvgfpgbdsohrns9\');
define(\'SECURE_AUTH_SALT\', \'pllenyye8zbtml91hekptc2clqr7bhvhlriecz5qozexfhiqptmcvxrlehj44c16\');
define(\'LOGGED_IN_SALT\',   \'9lyqc6qod0zdgyh6esp7bsxmpmuyp3h64m62pcnwxyefejh6tjykm7tpxhecg3xy\');
define(\'NONCE_SALT\',       \'ob0bq3fye46rubbgu5flycjuai4ygxqgxho8bb1k8t81mwhghcbkysrgxrjzx0fu\');

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = \'wp_\';

/**
 * WordPress Localized Language, defaults to English.
 *
 * Change this to localize WordPress.  A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de_DE.mo to wp-content/languages and set WPLANG to \'de_DE\' to enable German
 * language support.
 */
define (\'WPLANG\', \'\');

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
define(\'WP_DEBUG\', false);

/* That\'s all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined(\'ABSPATH\') )
    define(\'ABSPATH\', dirname(__FILE__) . \'/\');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . \'wp-settings.php\');

2 个回复
SO网友:Dhimas Ulung Pamungkas
$cap_type = \'post\';
$plural = \'Products\';
$single = \'Product\';
$cpt_name = \'products\';

$opts[\'supports\'] = array( \'products\', \'title\', \'editor\', \'thumbnail\', \'author\', \'revisions\' );
$opts[\'can_export\'] = TRUE;
$opts[\'capability_type\'] = $cap_type;
$opts[\'description\'] = \'\';
$opts[\'exclude_from_search\'] = FALSE;
$opts[\'has_archive\'] = TRUE;
$opts[\'hierarchical\'] = TRUE;
$opts[\'map_meta_cap\'] = TRUE;
$opts[\'menu_icon\'] = \'dashicons-products\';
$opts[\'menu_position\'] = 2;
$opts[\'public\'] = TRUE;
$opts[\'publicly_queryable\'] = TRUE;
$opts[\'query_var\'] = TRUE;
$opts[\'register_meta_box_cb\'] = \'\';
$opts[\'rewrite\'] = array(\'slug\'=>\'products\', \'with_front\'=>false);
$opts[\'show_in_admin_bar\'] = TRUE;
$opts[\'show_in_menu\'] = TRUE;
$opts[\'show_in_nav_menu\'] = TRUE;

$opts[\'labels\'][\'add_new\'] = esc_html__( "Add New", \'wisdom\' );
$opts[\'labels\'][\'add_new_item\'] = esc_html__( "Add New {$single}", \'wisdom\' );
$opts[\'labels\'][\'all_items\'] = esc_html__( "All {$plural}", \'wisdom\' );
$opts[\'labels\'][\'edit_item\'] = esc_html__( "Edit {$single}" , \'wisdom\' );
$opts[\'labels\'][\'menu_name\'] = esc_html__( $plural, \'wisdom\' );
$opts[\'labels\'][\'name\'] = esc_html__( $plural, \'wisdom\' );
$opts[\'labels\'][\'name_admin_bar\'] = esc_html__( $single, \'wisdom\' );
$opts[\'labels\'][\'new_item\'] = esc_html__( "New {$single}", \'wisdom\' );
$opts[\'labels\'][\'not_found\'] = esc_html__( "No {$single} found", \'wisdom\');
$opts[\'labels\'][\'not_found_in_trash\'] = esc_html__( "Not found {$plural} in Trash", \'wisdom\' );
$opts[\'labels\'][\'parent_item_colon\'] = esc_html__( "Parent {$plural} :", \'wisdom\' );
$opts[\'labels\'][\'search_items\'] = esc_html__( "Search {$plural}", \'wisdom\' );
$opts[\'labels\'][\'singular_name\'] = esc_html__( $single, \'wisdom\' );
$opts[\'labels\'][\'view_item\'] = esc_html__( "View {$single}", \'wisdom\' );
register_post_type( strtolower( $cpt_name ), $opts );

try this

SO网友:squarecandy

首先,确保基本要素都到位:

  • register_post_type 包括\'revisions\'supports args数组WP_POST_REVISIONS 在wp config中未定义或设置为true。php打开屏幕选项并确保;修订版;已选中。(虽然我认为这只控制了大的元框,无论如何设置,小的“修订”链接都应该出现在“可见性”下面)
接下来,确保您实际有两个版本的文章要测试。

为您的CPT创建一个包含任何内容的新测试帖子,对内容进行更改/编辑并更新(不要只按更新-确保实际更改某些内容)您现在应该可以看到可用的修订,并可以恢复到旧版本。

结束

相关推荐

How to delete post revisions?

我没有设置修订数量的限制,这使得我的一些帖子有20多个修订,那么如何删除这些修订呢?顺便说一下,我正在使用WPMU,并且有很多博客,那么如何删除我所有博客的WordPress修订版呢?