Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
2  
I think you mean terms, not taxonomies. –  vancoder Apr 4 '13 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 Apr 5 '13 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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