We at BlogVault arrived at a situation where we needed to convert some of our pages into posts. We faced a few problems but managed to overcome them. Before telling you how we did it, let us remind you to take backups of your website. So that if something goes wrong, you still have the blog posts you have written and can quickly restore them. But if you are not using a backup service, then check out this backup plugin guide to choosing the best WordPress backup plugin. That said, let’s find out how to convert a page into a post or vice-versa in WordPress.
One’s common sense will tell to create a new post – copy everything from content to title as in page to the new post – delete the old page and finally publish the post! This should work great is your permalink is set to WordPress default (or you have some custom setting that handles it somehow using the id). But in our case our permalink setting was:
Post name: http://127.0.0.1/wordpress/sample-post/
So when we visited the new (post) link after deleting the old page, we got 404 – Page not found!
Understanding the issue
As you can see the same thing works for a particular permalink setting but fails for another. This can be explained as – WordPress maintains a common (database) table for both post and page under the name ‘wp_posts’. As each entry in the table has its own unique id, when we try to locate them using id in permalink (as WordPress default) we face no problem.
However, it’s not the same with our permalink setting. Due to some reason, on deleting a page (or post) from admin panel, WordPress does not immediately remove their corresponding entry from the database. So when resolving the address by post name, WordPress finds the earlier entry (page in our case) which is marked deleted, hence giving the 404 not found error.
One simple solution is using plugins exclusively made for this purpose. Some of them are:
However, in case you don’t mind getting your hands dirty and saving your site with a load of an extra plugin, you can follow these steps (with extreme precautions).
- Get access to your WordPress database. You may use phpmyadmin for that.
- Open the wp_posts table.
- Locate your post entry and replace its ‘post_type’ from ‘page’ to ‘post’ or vice versa.
In case you already created a new post as in our case and are now getting the 404 error, simply delete your earlier (deprecated) entry.
SQL query for same will be:
Post to page
UPDATE wp_posts SET post_type=’page’ WHERE id=<your_post_id>;
Page to post
UPDATE wp_posts SET post_type=’post’ WHERE id=<your_post_id>;
It’s worth reminding that before you convert your page into a post, take backups. So that if something goes wrong, you still have the blog posts you have written and can quickly restore them. But if you are not using a backup service, then check out this backup plugin guide to choosing the best WordPress backup plugin.