Update WordPress Post Type using SQL

[kb_terms]

If you need to switch post types in WordPress, you can do this quickly using the free plugin “Post Type Switcher” available on the WordPress respository (https://wordpress.org/plugins/post-type-switcher/).

If you need to do this programmatically, it’s also simple to do using some basic SQL. In this video I explain how.

Don’t forget to backup first!

SQL

SQL Used (adapt table names and post types for your own database and requirements) To display your post types:
SELECT DISTINCT `post_type `
FROM wp_posts
To update using ID:
UPDATE wp_posts
SET post_type = 'knowledgebase'
WHERE id in (1783,1784,1785,1786, 1787,1788)
To update everything
UPDATE wp_posts
SET post_type = 'knowledgebase'
WHERE post_type = 'post'
Article published 28th May 2021
Last modified 02nd November 2023

Loading