Wordpress Custom Table or Custom Post Types?

2020-02-29 03:14发布

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?

2条回答
男人必须洒脱
2楼-- · 2020-02-29 03:36
  • Create an Custom post type
  • add the custom fields to that custom post type for different fields you need,

There is no need of creating table manually,

and you can apply the sorting on some custom field you added to the post type,

查看更多
你好瞎i
3楼-- · 2020-02-29 03:42

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:

http://codex.wordpress.org/Post_Types http://codex.wordpress.org/Function_Reference/add_meta_box http://codex.wordpress.org/Function_Reference/register_taxonomy (optionaly) http://codex.wordpress.org/Function_Reference/get_post_meta http://codex.wordpress.org/Function_Reference/add_post_meta

I hope you this will help you :)

查看更多
登录 后发表回答