WordPress的自定义表格或自定义帖子类型? [英] Wordpress Custom Table or Custom Post Types?

查看:127
本文介绍了WordPress的自定义表格或自定义帖子类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用wordpress制作一个包含职位的网站,并且我想知道存储公司详细信息的最佳方法,因为每个职位都必须链接到公司.

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.

通常,我只需要在数据库中建立一个company表,并在每个职位中添加一个公司ID,然后加入以获得公司详细信息.

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.

但是,我经常遇到这样的想法:在新的表中,它并不是总是在Wordpress开发中最好的选择(例如这里).相反,我最好使用自定义帖子类型.

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?

推荐答案

我认为最好将自定义帖子类型与帖子元一起使用,并将其与元框结合使用.这样,您将可以轻松管理公司,但仍可以通过WP_Query类对公司进行自定义查询.

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 :

请注意,每当我想向公司添加新数据时,我都可以随意添加一些额外的元框,然后将这些额外的数据另存为该帖子的元数据.这种方法只需几分钟即可扩展标准数据实体.

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.

您需要什么:

http://codex.wordpress.org/Post_Types http://codex.wordpress.org/Function_Reference/add_meta_box http://codex.wordpress.org/Function_Reference/register_taxonomy (可选) 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 :)

这篇关于WordPress的自定义表格或自定义帖子类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆