admin管理员组文章数量:1390626
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 badges2 Answers
Reset to default 1You'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:
- Roll your own metabox, and hide/disable the default one for this post type.
- slam 2 select fields in it, populated with all of the Stones terms
- add a little JS to make sure that when an item is selected in one, it's hidden from the other dropdown.
- 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
.
本文标签: Use the same taxonomy twice on the same post type
版权声明:本文标题:Use the same taxonomy twice on the same post type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744631815a2616585.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论