I've got a vexing how-to that I've not found any help on. I have a custom post type that has a custom field with a date in it (format: yyyy-mm-dd-t). When a post is published or edited, I would like to have a function that automatically populates a hierarchical taxonomy with the year and date.

So for example, if I entered "2003-03-15-1" into the custom date field, I would like it to include the custom taxonomy "2003" and its child taxonomy "03". But while I've seen code that will populate the parent taxonomy, I've not found anything that tells me how to populate the parent and the child.

Surely such a thing is possible, right?

  • 2
    I think you mean terms, not taxonomies.
    – vancoder
    Commented Apr 4, 2013 at 22:15
  • 3
    WordPress isn't going to let you add terms with non-unique slugs, so for example 2003-03 and 2004-03 will require that one of the 03 terms have something unique appended. But disregarding that, can I ask why you need to do this? Perhaps the end result you'd like to achieve can be accomplished with the already-existing meta data, since posts can be queried and sorted on that data.
    – Milo
    Commented Apr 5, 2013 at 4:00

1 Answer 1


IF it were me, I would make "Year" and "Month" separate taxonomies rather than using a hierarchical taxonomy. If you do it that way, here's a good answer to use as a reference. This will solve the "unique slug" issues you'll run into using hierarchical taxonomies.

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.