最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Use the same taxonomy twice on the same post type?

programmeradmin2浏览0评论

Hello there basically I am quite good with WP however it is not easy for me to find a solution to this problem:

  • There is an taxonomy which will consist of hundreds and mayby thousands of items. This taxonomy is called "Stones".
  • There is a custom post type called "item" (for sale) which consists of 1..n "stones" in the "main part" and of 1..n "stones" in the "additional part"

In other words the same taxonomy should appear using different labels for the same post type twice (Stones contained in the main part and stones contained in the additional part).

Of course it would be easy just to create two different custom taxonomies, but the challange here is that the items of the two taxonomies should be identical and should be identically inserted / updated / deleted.

Can somebody think of an solution for this?

Hello there basically I am quite good with WP however it is not easy for me to find a solution to this problem:

  • There is an taxonomy which will consist of hundreds and mayby thousands of items. This taxonomy is called "Stones".
  • There is a custom post type called "item" (for sale) which consists of 1..n "stones" in the "main part" and of 1..n "stones" in the "additional part"

In other words the same taxonomy should appear using different labels for the same post type twice (Stones contained in the main part and stones contained in the additional part).

Of course it would be easy just to create two different custom taxonomies, but the challange here is that the items of the two taxonomies should be identical and should be identically inserted / updated / deleted.

Can somebody think of an solution for this?

Share Improve this question asked Apr 29, 2014 at 0:47 BlackbamBlackbam 57511 silver badges28 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

You'll have to store some sort of meta data with each post that denotes the relationship of each term. Hide the normal taxonomy meta box and provide your own meta box UI that allows selection of terms, and upon save adds post meta with term + type of relationship, in addition to setting the object terms.

Not to always resort to Plugins when unnecessary, but Advanced Custom Fields has a Taxonomy Field. Allows you to stick another dropdown/etc. field on your post type.

If interested, I'd look into where it stores it. If stored in the wp_terms table, you will need a way to differentiate between "Main" and "additional" parts.

EDIT

My idea for a solution:

  1. Roll your own metabox, and hide/disable the default one for this post type.
  2. slam 2 select fields in it, populated with all of the Stones terms
  3. add a little JS to make sure that when an item is selected in one, it's hidden from the other dropdown.
  4. When saving, save the selections in the wp_terms table, AS WELL as postmeta.

This will give you the ability to include these items in "by Stone" searches (attached directly to the term, so you can use WP_Query's tax_query), they will appear in categorized archives, etc. Annd you can check on postmeta to see which is the primary_stone and which is the additional.

发布评论

评论列表(0)

  1. 暂无评论