0

From a clean install of WordPress 4.6.1, I am noticing that when I create a page based on a custom post type, the page displays. But if I go back to my functions.php file, and accidently remove the register code set in place (i.e.)

add_action( 'init', 'create_post_type' );
function create_post_type() {
  $args = array (
      'public' => true,
      'has_archive' => true,
      'show_ui' => true,
      'supports' => array('revision','title','editor','author', 'thumbnail', 'custom-fields'), 
      'labels' => array(
        'name' => __( 'Events' ),
        'singular_name' => __( 'Event' )
      )
  );
  register_post_type('events', $args);
}

...and save the file, the custom post type page is gone from the UI and also from the front of the site, but it still lives in the mySQL database table *_posts.

When I attempt to add the code back into the functions.php file, and save it, it does not display the custom post page...still blank.

How can we display the post back again?

1

What you're observing is normal behavior. Registering a post type does not add any data to the database, but adding a new post once the post type has been registered does add data to the DB. Removing the post type registration code will not remove data.

Head over to Settings > Permalinks and click Save Changes. That should fix the 404 error.

Note that if the post type name is changed, when re-adding the post type, the data will not be available for the newly named post type.

  • Thanks for the heads up - but this process does not re-add the link onto my edit.php?post_type=events page in the admin. the link on that admin page is gone, yet the post is still in the database. Also the post type name didn't change in my code. I made an attempt to re-add that same exact code as I had before. – klewis Oct 5 '16 at 20:23
  • Added a note to the answer. I was working on another one of your questions which was interesting btw, but a dupe and was deleted, but I noticed that you named your event post type mevents there, and in this question the name is events. If the post type name was changed, then the data would be associated with the old post type name, mevents. Is that what happened here? There are plugins that will let you change post type names easily if this is the case, or you can just start over with the new name if you want. – Dave Romsey Oct 5 '16 at 20:29
  • You are the man!!! Thank you Dave for pointing that out. That was an overlook on my part. I re-added in the proper name and now everything is working well again. Steak on me when you come to town! As far as that deleted posted - I found my solution to adding my custom post type to the At A Glance box by the following author - clicknathan.com/web-design/… – klewis Oct 5 '16 at 20:34
  • Thanks! I'm glad that worked out. I've been in the same boat and I learned something from your first question too. Cheers! – Dave Romsey Oct 5 '16 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.