gray gray - 1 year ago 119
PHP Question

Wordpress Custom Table or Custom Post Types?

I am using wordpress to make a site which has job posts, and I want to know the best way to go about storing company details, as each job post must be linked to a company.

Normally I would have just set up a companies table in my database, and put a company ID within each job post, then joined to get company details.

However I have often come across the idea that it's not always the best option in Wordpress development to create new tables (such as here). Instead I would be better using custom post types.

But how would this work to store company details? Would it be right to create a custom post type for companies, and then add a new post for each company? And then use custom fields to store data about each?

Or would I be best off creating new database tables? What is better and why?

Answer Source

I suppose it is the best to use custom post types with post meta in conjuction with meta boxes. This way, you will be able to manage in ease your companies, and yet, you will be able to operate custom queries on companies via the WP_Query class.

Currently I am building a business directory for a my client, so I decide to use the custom post types because of flexibility. Also I made a custom script for managing company information in conjuction with post meta.

Take a look in the screen shot to undestraint what I mean :

enter image description here

Note that whenever I like to add new data to companies, I am free to just add some extra meta boxes, and then save the extra data as meta data for the post. This way is matter of minutes to extend a standart data entity.

What you need: (optionaly)

I hope you this will help you :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download