Custom Post Type Tables


WordPress stores custom post types in the default posts table (typically wp_posts), which is fine for most setups. In the majority of use cases, WordPress sites are not used to store in excess of thousands of posts, and so this sort of setup doesn’t place much additional load on servers.

In cases where the site generates a significant amount of posts across multiple post types though, queries can become very expensive – especially where meta generating plugins such as Advanced Custom Fields are involved. Where a WordPress site is expected to generate thousands of posts (and subsequently, many thousands of rows of post meta) queries can be sped up significantly by splitting out data into separate tables. This plugin splits out data by post type, creating additional tables for each custom post type used. A ‘product’ custom post type for example will have its posts stored in product and its meta in product_meta.

If you are using WordPress a little bit longer, you already know that it is an incredibly versatile platform. With its numerous features and extensions, however, it can sometimes be difficult to keep track of and find the right method for managing your content. This is where the use of WordPress custom post types in separate tables comes in!

By outsourcing your custom post types to separate tables, you can better organize and manage your content. It also allows you to have better control over your database and process queries more quickly and efficiently, which can positively impact the performance of your website.

Moreover, outsourcing custom post types to separate tables can also help improve the security of your website. By separating your content into separate tables, you can prevent malware or hackers from accessing your entire database.

Overall, outsourcing WordPress custom post types to separate tables offers a range of benefits for your website. It can improve the organization and management of your content, optimize the performance of your website, and increase your security. If you want to take your website to the next level, you should consider outsourcing your custom post types to separate tables!

Works with

  • Multisite Installations
  • Woocommerce
  • YOAST etc.
  • Advanced Custom Fields
  • … and all other registered active custom post types


As soon as you select a Custom Post Type, a new table is created in the database. This table will be used for all entries of this custom post type.

When you migrate the existing entries, the data from the old table is copied to the new table. This process is not reversible.

Backup your database before migrating in case something doesn’t work as you expect.


Each new post and meta table is created to the same structure as the WordPress default post and meta tables. This streamlines the storage process and means that WordPress is capable of interpreting the data wherever it would normally use a wp_posts row, e.g. on the admin edit post pages, admin post listing pages, and in the wp-posts functions (e.g. get_post()).

When new posts are created, a row is inserted into the wp_posts table (as normal) and an automatic MySQL trigger is used to copy this data into the new custom table. Queries to the wp_posts and wp_postmeta table are then rewritten to use the custom table, so that all future lookups and updates made by WordPress and its plugins are made to the new tables. The original wp_posts row is retained for lookup purposes, so that we can determine the post type (and therefore custom table) when there is only a post ID available to work with. Since these lookups are (usually) only necessary in the WordPress admin and exclusively use the primary key, they do not significantly increase the load of the request. Additionally, each ID lookup is made a maximum of once per request and the result is cached on a per-request basis.

To minimise unecessary lookups when writing your own queries, specify the post type you are looking for whenever possible. This will allow the plugin to simply parse the table from the query without having to lookup the post type in the wp_posts table.

Filter Hooks


Customise what capability the settings page should be limited to. Default is ‘manage_options’.


Developed with ♥ by Sebastian.

This plugin was initially created for own usage to get a big database cleaner.

Check out the GitHub repository and submit pull requests or open issues


  • Find orphaned meta values and copy to new custom table
  • Trigger optimization

  • Hotfix: Altered correct auto_increment field for meta table


  • Removed autoincrement from copied table as it is controles by the posts_table (Revert CPT Tables and migrate them again to get the changes working)


  • Bugfix in cleanup-cronjob


  • Revert tables on plugin deactivation


  • German translation
  • Add missing migrated post_types, when the custom table exists
  • Fixed bug on deactivate the plugin


  • Load plugin the right time when all post types are registered
  • Refactoring and bugfixing
  • Added language pot template


  • Clear orphaned post_types from activated entries
  • You can activate a cronjob for table optimization in the settings


  • Automatically remove orphaned entries in the main post table under certain conditions


  • Re-create triggers if they don’t exist


  • tested with WordPress 6.2


  • Fixed debugger warnings
  • Clean up code
  • Escape vars
  • Sanitize vars
  • Refactoring


  • Added _ to accepted chars of post type



The plugin can be found it the WordPress Plugin Directory. Search for «Custom Post Type Tables».

Manual Installation

  1. Upload the entire /cpt-tables directory to the /wp-content/plugins/ directory.
  2. Activate «Custom Post Type Tables» through the ‘Plugins’ menu in WordPress.
  3. Do a database backup manually or use a third party tool
  4. Go to «Settings / CPT Tables»
  5. Migrate the post types you want


23 de mayo de 2023 2 replies
Hello Sebastian, Thank you for this amazing plugin. I'm encountering an error after migrating WooCommerce products. Additionally, I would like to ask if this is compatible with Gutenberg templates? Fatal error: Uncaught Exception: Trigger already exists in /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-content/plugins/cpt-tables/lib/Db.php:62 Stack trace: #0 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-content/plugins/cpt-tables/lib/Triggers.php(210): WPCPT_Tables_Db->query('CREATE TRIGGER ...') #1 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-content/plugins/cpt-tables/lib/Triggers.php(62): WPCPT_Tables_Triggers->insertMetaTrigger(Array) #2 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-content/plugins/cpt-tables/core.php(179): WPCPT_Tables_Triggers->create(Array) #3 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-content/plugins/cpt-tables/core.php(92): WPCPT_Tables_Core->checkExistingTriggers() #4 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-includes/class-wp-hook.php(308): WPCPT_Tables_Core->load('') #5 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array) #6 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #7 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-settings.php(486): do_action('plugins_loaded') #8 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-config.php(93): require_once('/Users/admin/Lo...') #9 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-load.php(50): require_once('/Users/admin/Lo...') #10 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-admin/admin.php(34): require_once('/Users/admin/Lo...') #11 /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-admin/plugins.php(10): require_once('/Users/admin/Lo...') #12 {main} thrown in /Users/admin/Local Sites/woocommerce-invoice-manager/app/public/wp-content/plugins/cpt-tables/lib/Db.php on line 62
19 de abril de 2023 1 reply
Wonderful idea behind the plugin and really useful tool. I just started with this and mostly the results are very encouraging and positively impactful. The support is also very responsive and the author receives feedback with an open mind. I have great expectations from this plugin and will continue experimenting with it. Thank you. Edit: I have changed my star rating to 5. Totally impressed with how quickly the author responded to a few minor issues and his maturity to get these fixed quickly. Great commitment toward consistency and quality.
2 de abril de 2023 2 replies
بعد از مهاجرت به جدول جدید محصولات، ما متوجه شدیم که تمامی دیدگاها و نظرات در محصولات حذف و ناپدید شده اند. !حتی نظرات و دیدگاهای جدید ذخیره نمیشه After migrating to the new table of products, we noticed that all the views and comments on the products have been deleted and disappeared. !Even new comments and opinions are not saved
Leer todas las 3 reseñas

Colaboradores y desarrolladores

«Custom Post Type Tables» es un software de código abierto. Las siguientes personas han colaborado con este plugin.


«Custom Post Type Tables» ha sido traducido a 1 idioma local. Gracias a los traductores por sus contribuciones.

Traduce «Custom Post Type Tables» a tu idioma.

¿Interesado en el desarrollo?

Revisa el código , echa un vistazo al repositorio SVN o suscríbete al registro de desarrollo por RSS.