0

I'm making a custom theme for a client who has need of two custom post types. I'd like to join them together (it's a one-on-many connection) and thus was thinking of adding a column to the posts table to store the connection.

Of course I've read that I could use the posts_meta table to store extra info about some posts but to be fair, it feels like a roundabout way to do it, especially if you could just store the information in a column.

So I was wondering if adding a column to the standard wp posts table was a good idea or no.

  • 1
    the answer is "no" – Mark Kaplun Mar 8 '18 at 10:52
  • Could you at least elaborate why not, @MarkKaplun? – Alex Hermans Mar 8 '18 at 10:52
  • A new table entirely with the connection would be better. – Jacob Peattie Mar 8 '18 at 11:06
  • 1
    in general, changing internals of software that you didn't write, where the software did not explicitly declare to support such a change, is always a bad idea unless you are happy to maintain a fork. – Mark Kaplun Mar 8 '18 at 11:17
  • 1
    I'd rather recommend using taxonomies or Posts 2 Posts for that instead of altering the posts table in such a way. – swissspidy Mar 8 '18 at 12:48
2

Adding another column wouldn't break the code at all .. but it might create issues while updating WordPress to a new version ..

It's better to add another table having fields (ID PK Auto Increment, post_id FK, <your-custom-column>) .. the post_id field will point to ID field in wp_posts table as a foreign key!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.