Mysql – Change name of a post type without losing posts

custom-post-typeMySQLWordpress

I have made a site that uses custom posts types for a projects section.

I need to change the post type from 'projects' to 'galleries' but as I have already uploaded a bunch of projects was wondering how I would do this with as little as possible hassle (I do not want to have to re-upload all the images and text etc)

I found a few articles that tell me to do a SQL query to rename the posts

UPDATE  `wp_posts` 
    SET  `post_type` =  '<new post type name>' 
    WHERE  `post_type` = '<old post type name>';

And this one for the taxonomy

UPDATE  `wp_term_taxonomy` 
    SET  `taxonomy` =  '<new taxonomy name>' 
    WHERE  `taxonomy` = '<old taxonomy name>';

I just have no idea what I am supposed to do with this code. If it is SQL do I run it in a php file or is there some sort of 'terminal' that can be found in the WP dashboard or cPanel of my site?

Below is how I created my post type (Not sure if this helps)

function create_my_post_types() {
    //projects 
    register_post_type(
      'Projects', array('label' => 'Projects','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true, 'menu_position' => 8,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => '','with_front' => '0'),'query_var' => true,'exclude_from_search' => false,'supports' => array('title','editor','thumbnail'),'taxonomies' => array('category',),'labels' => array (
      'name' => 'Projects',
      'singular_name' => 'Project',
      'menu_name' => 'Projects',
      'add_new' => 'Add New Project',
      'add_new_item' => 'Add New Project',
      'edit' => 'Edit',
      'edit_item' => 'Edit Project',
      'new_item' => 'New Project',
      'view' => 'View Project',
      'view_item' => 'View Project',
      'search_items' => 'Search Projects',
      'not_found' => 'No Projects Found',
      'not_found_in_trash' => 'No Projects Found in Trash',
      'parent' => 'Parent Projects',
    ),) );  

} // end create_my_post_types

Best Answer

If you have CPanel access, you can look for PHPMyAdmin and run the SQL code there.

  1. Go to PHPMyAdmin.

  2. Select your wordpress database from the left.

  3. RECOMMENDED: Backup your database first, by going to the export tab at the top and doing a quick export.

  4. Select "SQL" from the top tabs.

  5. Copy your SQL queries in the huge textarea, and click Go.

Hope it works!

Related Topic