Enabled Revisions to existing custom post type not working Wordpress

I am trying to enable revisions for an existing custom post type. As the post type was already created about 2 years ago so where the post type was register I added revisions to the supports array.

Earlier my code was like:

   $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);

And now it looks like:

   $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);

This code didn't enable revisions in the custom post type.

Then I found another code which I added to my theme's function.php:

function add_revisions_custom_post()
{
    add_post_type_support( 'products', 'revisions' );
}
add_action('init','add_revisions_custom_post');

This one is also not working.

Can anyone suggest me how I can enable revisions?

Thanks in advance.

EDIT: Here is my wp-config.php file.

?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');

Topic revisions custom-post-types Wordpress

Category Web


First, make sure the basics are all in place:

  • register_post_type includes 'revisions' in the supports args array
  • WP_POST_REVISIONS is either not defined or set to true in wp-config.php
  • open Screen Options and make sure "Revisions" is checked. (Though I think this only controls the big meta box, and the small "revisions" link should appear below "visibility" no matter how this is set)

Next, make sure you actually have two versions of the post you're trying to test.

  • Create a new test post of your CPT with any content
  • Make a change/edit to the content and Update (don't just press Update - make sure to actually change something)

You should now see revisions available and be able to revert to old versions.


$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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.