CPT UI and custom database table

I am new in wordpress dev. I am building a plugin and I have a question I have a custom table in the database Is there any way to create a Custom Post type connected to this table? I am using CPT ui btw How can I approach this problem? any ideas?

Thank you in advance

Topic plugin-development Wordpress

Category Web


No, a custom post type is still a post in the posts table, you can't connect it because it's not a connection. It's a column in a table.

If you want to have the same UI as posts but for a custom table, you're going to have to implement it yourself:

  • with a custom settings page
  • custom SQL code
  • A custom implementation of WP_List_Table, create a class that inherits from WP_List_Table and implement the methods so that it loads your database rows
  • Another custom settings page that will act as the new/add/edit screen, implemented from scratch

Suffice to say this task is too broad to answer in a single question/answer, and you're facing a lot of manual recreation, including building pagination from scratch, etc

It would be easier to use a real custom post type, or to build a bespoke UI. My recommendation would be a JS powered UI using REST endpoints

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.