change or set post type wordpress

You can change or set the post type in WordPress using code. To do this:

  1. Identify the Post Type: Use the get_post_type() function to retrieve the current post type.
$post_type = get_post_type( $post_id );
  1. Change Post Type: Use the set_post_type() function to change the post type of a specific post.
set_post_type( $post_id, $post_type );
  1. Register a New Post Type: To create a new post type, use the register_post_type() function in your theme's functions.php file or in a custom plugin.
function custom_post_type() {
    $args = array(
        'public' => true,
        'label'  => 'Custom Post Type',
        // Add more arguments as needed
    );
    register_post_type( 'custom_post_type', $args );
}
add_action( 'init', 'custom_post_type' );

Replace 'Custom Post Type' with your desired label and modify the arguments array as per your requirements.

Remember to replace $post_id with the ID of the post you want to change, and adjust the post type and other parameters according to your needs. Always make a backup and test changes on a staging site before implementing them on a live site.