8

I currently put my hands into WP taxonomy and terms to find solutions for my project. I knew that it's not possible to have same terms slug when creating a term with wp_insert_term in one Custom Taxonomy and between different Custom Taxonomies, but i would like to have different terms linked to the same url (so slugs are involved in it) and get all the related posts to these different terms.

Say a custom Taxonomy 'tax' and the following terms in it :

a (slug : a) 
--b (slug : b)
-c (slug : c)
---d (slug : d)

I can access the different tax term with the following links :

/tax/a
/tax/b
/tax/c
/tax/d

If i want to insert a term with wp_insert_term('e','tax',array(slug=>'a'), WP will modify the slug to 'a1' because slugs should be unique...

So, seems impossible to redirect different terms to the same slug/url and get all the custom posts from 'a' and 'e'.

And what about alias_of argument ? Can't find any full documentation about it . Wasn't it precisely for that kind of issue ? I've inserted several terms with that kind of code : wp_insert_term('e','tax',array(slug=>'e','alias_of'=>'a') but it doesn't change anything, WP creates different unique slugs for all my entries and doesn't care about alias_of.

Is Anybody here can clarify this or have a solution ?

thanks a lot !

EDIT

Seems to be related to term_group , a feature that isn't really yet supported by WP. There is a term_group field in wp_terms database . The value of this field is set on term creation wp_insert_term($name,$taxonomy,array('alias_of' => $slug) and retrieve when get a term with (for ex get_term_by()->term_group function). There should be a way to query this but with the terms metas support, i don't really see the interest ...

6
  • 3
    I could only find the alias_of implementation in the wp_insert_term() and wp_update_term() functions so I would think that this is still only half baked featured in the core.
    – birgire
    Commented Dec 15, 2015 at 15:05
  • Yeps, same for me ... but this feature would be interesting because i need a way to display all the posts related to multiple Taxonomy terms on a single url within the same slug... and by the way, make relationships between same term name in different level of the Taxonomy. I could imagine alias_of announce what we will be able to do in future, but when :)
    – Polykrom
    Commented Dec 15, 2015 at 15:17
  • 1
    Maybe this posting, found on the net, could help you a little to enlighten some? I am not sure but it could not harm to read imho. As it seems an interesting item which is not clearly documented.
    – Charles
    Commented Dec 15, 2015 at 15:45
  • @Charles , thanks for the link ... it seems groups and alias aren't supported yet , this post seems to confirm that... Weird.. it looks too that these "on hold" features are in core for years :-/
    – Polykrom
    Commented Dec 15, 2015 at 16:21
  • 1
    I just wanted to clarify "I knew that it's not possible to have same terms slug when creating a term with wp_insert_term in one Custom Taxonomy and between different Custom Taxonomies". It is now possible to have the same slug used in multiple taxonomies (as of version 4.2 I believe)
    – Shawn H
    Commented Jan 19, 2016 at 1:49

1 Answer 1

4

In the Code Reference it says:

'alias_of'

(string) Slug of the term to make this term an alias of. Default empty string. Accepts a term slug.

This makes a term an alias of another term. Using your example this is how you would use it:

wp_insert_term( 'e', 'tax', array( 'alias_of' => 'a' ) );

This would create a new term e in the tax taxonomy without its own slug, and posts in e would also show up under the a slug.

2
  • To clarify this a bit; you're saying http://example.com/tax/e/ and http://example.com/tax/a/ would show the same posts assigned to category e?
    – Howdy_McGee
    Commented Feb 16, 2016 at 19:31
  • 2
    No, in my example, http://example.com/tax/e/ would not exist, as the term e would not have been assigned a slug. All posts using e would show up in http://example.com/tax/a/. Commented Feb 16, 2016 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.