Ideas
Allow Child Category To Have Multiple Parents
- There should be an option to allow child categories to belong to multiple parents.I outlined an example use for this feature at the end of this previous trac issue:http://core.trac.wordpress.org/ticket/12898Let's say I am geotargeting, and I have identified that the user is from Germany. I can then display posts from the category 'Germany'.But if I can make Germany a child category of two parent categories - 'European_Union' and 'German_Lanugage_Articles', I would then be able to easily display additional posts from these categories that are also relevant to German visitors.At the moment, WordPress would only allow Germany to be a member of one of these parent categories, but not both.I do not know of any ways to neatly acheve this without creating a custom MySQL table and code to support these multiple parent relationships.Posted: 4 years ago #
- If this helps, I am prepared to sponsor the implementation of this enhancement.If you're a core developer, shoot me a message and name your price.Posted: 4 years ago #
- I think this is probably plugin territory right now.Posted: 4 years ago #
- Taxonomy intersection like this can already be done by using a combination of Categories and Tags (the latter being orthogonal to category organization. A plugin to smooth this process would be good, but I don't think the core needs changing for this.Posted: 4 years ago #
- Functionally, this is an impossibility due to the present native structure of the database. I was hoping for feasability too, but I just found a workaround, based on how I structured my architecture. I'd suggest using tags, instead. Long story short, each category is a node in a Tree Data Structure with a pointer to its parent, but no pointers to children. This is for simplicity and ease of use. If they were to also store pointers to children, and modify the structure to permit multiple parents, the structure would become (I believe) exponentially more complicated, and hamper further development on more critical areas.For the technical details of how WordPress stores Categories, read on ... for the sake of brevity and clarity, I'll omit a few columns from a few tables, that didn't seem relevant.Categories are stored in the WordPress Database across three tables,
wp_terms
wp_term_taxonomy
andwp_term_relationships
iirc.wp_terms
stores aterm_id
,term_name
, andterm_slug
.term_id
is auto-incrementing, so the code starts by shoving the name and slug into thewp_terms
table, and then fetching the ID at which it was inserted. Name doesn't have to be unique, but slug does!Then we move onto thewp_term_taxonomy
table. As you may have noticed, we've been inserting words, but never saying what they meant! Thewp_term_taxonomy
table storesterm_taxonomy_id
,term_id
,taxonomy
,description
,parent
, andcount
. Now,count
simply stores (for category purposes) the number of events that are assigned to that category, ignoring child-categories. We can ignore it.term_taxonomy_id
is the auto incrementing id that bumps up whenever you add in a new taxonomy.term_id
is the term in question from thewp_terms
table. Notice that this table has no slot forname
. It simply links into thewp_terms
table, so you can have multiple term_taxonomies, pulling from the same name inwp_terms
.taxonomy
is what the term is to be considered. For our purposes, it will always be 'category'.description
is the description of the category, andparent
is an INT, containing the parent category (that really cool thing that we care about).wp_term_relationships
is simply tyingwp_term_taxonomy
in with actualobject_id
s (posts, etc.) It's the link between a post and its category, allowing you to create multiple entries, to link one post to multiple categories (because the link is stored seperately from either the parent or child).Now, the significance of all this. Categories are built as a tree data structure. Each category is a very simple construct, storing a payload and a pointer -- the normal, lightest way to build trees. Parents don't have pointers to their children, that could have to store anywhere from {no values} up to {thousands} or more. Instead, each category just stores (data) (parent) and you can travel up and down the tree. To travel to a parent, simply follow the pointer! To travel back down, it becomes a bit more cumbersome, as you have to scan the entire table for any elements that have the parent assigned as a parent -- fortunately, an easy task with a MySQL database, simply queryingSELECT * FROM
wp_term_taxonomy
WHEREparent
= '{$term_taxonomy}', where $term_taxonomy is theterm_taxonomy
of the parent in question!Long story short, use tags, because a plugin would have to rewrite the whole system, which is possible, but not very cost-effective!Posted: 4 years ago # - I need this function as in Drupal.
No it's not complecated. This is what I done in uni project, and is supposed very simple.The following required fields already exist in wp_term_taxonomyTerm ID | parent IDSo the tree is already complete. Now what you need is to allow duplicate term ID. That's for example:Tax ID | Term ID | parent ID
10 | 30 | 10
11 | 30 | 13That's for example
Taxonomy number 10 is a record of Term 30 (T-Shirt), which is a child of Term 10 (Woman Clothing)
Taxonomy number 11 is a record of Term 30 (T-Shirt), which is a child of Term 13 (Man Clothing)No it's not complicated, it's just un-thought.And for me, tagging sucks because there is no filter of Category vs Tag. And tag has no hierarchy, it SHOULD.Posted: 3 years ago # - Has anyone given any thought to Binh's solution. I can't find fault with it. Nice approachPosted: 2 years ago #
- The tag workaround is ok but as in life, sometimes there are more parents! Seriously though it does need a workaround other than tagging.Posted: 2 years ago #
- There are also custom taxonomies. So you make one called Languages, and list them all there. You make another called EU and list the nations there.Posted: 2 years ago #
- Even with a custom taxonomy the database index keyed on term_id-taxonomy does not allow multiple parents. Honestly all we need to do is change the key requirement on the wp_term_taxonomy table so that we can have multiple rows with the same term_id and taxonomy but different parent and then plugins can do their thing.Posted: 2 years ago #
Reply »
You must log in to post.
0 comments:
Post a Comment