This is a very short tutorial which will let to know how to Switch post type in Wordpress sites.
In this tutorial, I will share a simple code snippet which allows you to switch post type and also I have shared a WordPress Plugin named Post Type Switcher.
Related Articles
Use the below code at the end of the functions.php file and save. It will allow you to switch the post type from page to post and post to a page.
/** * Switch post type */ function switch_post_type ( $old_post_type, $new_post_type ){ global $wpdb; // Run the update query $wpdb->update( $wpdb->posts, // Set array( 'post_type' => $new_post_type), // Where array( 'post_type' => $old_post_type ) ); }
If you don’t want to use this code, then use Post Type Switcher WordPress plugin by John James Jacoby. This plugin will add a simple post-type drop-down on the post editor screen to switch the post type.
By using the Post Type Switcher plugin you can convert nearly every combination of posts, pages, and even custom post types:
- Page to Post
- Post to Page
- Post to Custom
- Custom to Custom
How to install Post Type Switcher plugin
The installation of this very simple as other plugins. If you have just started with WordPress, then check out:
- How to Install a WordPress Plugin
After the installation, click on Activate button to enable the plugin features on your WordPress site. See the below screenshots how it will look like after activated:
Hope this code will help you. Please do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
The post How to Switch Post Type in WordPress appeared first on FreeWebMentor.
This post first appeared on Programming Blog Focused On Web Technologies, please read the originial post: here