How to use custom database tables for custom post types?

I need to use an existing database table as a Custom Post Type (CPT) to integrate it with wordpress.

I’ve considered @boone-gorges thoughts here (should I?) and have decided, Yes, I need to use a custom table (mostly for indexing of the 20+ “custom meta” fields that would get bogged in wordpress’ native handling of custom meta.)

Aside from home-grown display and usage of data, I need tight integration with WordPress (acts and behaves like CPT) so that I can:

  • Call the CPT via the loop
  • Utilize custom taxonomies
  • Integrate with Posts to Posts
  • Use various other plugins (bbPress Topics for Posts, Popularity plugins, etc… ) on that CPT

Editing / Updating through WP would be a bonus – though not necessary (the table will be edited mostly via external programs, which is another reason it needs to be separate).

Is there a slick way to make this happen? Perhaps implementing hooks that hijacks calls to that CPT and directs them to the other table?

I’m looking at Pods – but this seems like overkill.

1 Answer
1

My educated guess you will drown in edge cases, exploding in your face, if you try to shard specific post type in separate table.

Since you seem to be actually concerned with meta rather than posts themselves, you could:

  • implement custom table for it
  • use Metadata API to store it in separate table, while retaining some degree of API compatibility.

Leave a Comment