- In looking through the code for Pippin Williamson's Easy Digital
Downloads, I notice that he uses custom tables AND custom post types.
- I also see (roughly) the same Tables/Custom Post Types config in Gravity Forms, GiveWP and so many other popular plugins.
Note: On the "Should You Do Custom Tables" argument, Pippin provides his rational for Custom Tables in this excellent post.
There used to be a mentality among WordPress plugin developers that you should never use custom tables in your plugin because it wasn’t the “WordPress” way. Let’s start by throwing that attitude out the window.
When it comes to storing large amounts of data that does not very closely mimic existing WordPress database schemas, you should absolutely use custom tables. Choosing not to use a custom table will likely cause more harm than good. While it’s possible to store almost anything you want as a custom post type in the wp_posts table, that does not mean you should or that it is even a remotely good idea.
Given these realities, I'd like to skip the usual "You should never do this" argument for now. This thing is happening :) What I need to know is how is it done?
Problem: I do not understand how the relationship(s) between the Custom Post Type and the Custom Table are established and maintained.
- Should I store the Custom Post Type data in the Custom Table (vs. wp_posts)?
- Should I store the Custom Post Type's metabox data only in the Custom Table?
- Do I use the save_posts hook to handle DB Crud?
Please advise.
Thanks