Using a hierarchal custom taxonomy associated with a custom post type, I need:

(1) To change the admin meta-box to a drop-down menu to make sure the post has only one term associated. The drop-down menu should show just the latest children terms, so let us say, for example, I have those two hierarchical terms:

  • Zone X
    --> Package X (Zone X's child)
    ----> District X (Package X's child)

  • Zone Y
    --> Package Y (Zone Y's child)
    ----> District Y (Package Y's child)

I want the drop-down to show only the latest children: District X and District Y.

(2) To automatically select all parents of a selected child term when saving the post. So, let us say the user chose District Y in my previous example, then both Package Y and Zone Y should be selected as well, behind the scenes.

Could anyone help me with that please, or point me out to any helpful reference?
Thanks in advanced,

1 Answer 1


I am not sure about (1) but you will likely need to create your own metabox from scratch and replace native one with it. See add_meta_box() in Codex for starters.

(2) to me seems to me as working against the system a bit. There is no point in hierarchy if your post belongs to whole hierarchy tree. On other hand this really needs to be put in context of how you will need to retrieve the data.

  • (2) Well, I can say that, actually. In fact, the needing for a hierarchical taxonomy in my case isn't for tagging & retrieving later purposes. You can think of it like that I need an interface to be able to connect every taxonomy item (child) to a specified group of parents to complete the tree, in a way that I'm just making use of the native taxonomy interface here.
    – Mamouneyya
    May 12, 2011 at 13:09
  • To understand this needing you can think of what I'm gonna use them for. I want to classify schools that are being built in different zones. Every zone is spitted into different packages. In the same way, every package is spitted into different districts. However, as you may guess, the end-user shouldn't have to specify those three levels everytime he adds a school. I should specify the tree and let WP know all level values above the chose District. So now that you know.. do you have a better way to implement it?
    – Mamouneyya
    May 12, 2011 at 13:17
  • Forgot to mention the map part here. There will be a map for collecting and filtering the displayed schools on a live map according to the Zone/Package/District. So I think that hierarchical taxonomy really makes implementing this part easier and cleaner.
    – Mamouneyya
    May 12, 2011 at 13:21
  • @Mamouneyya why don't you just handle it on fetch stage? Assign districts. Then if you need zone/package - fetch child districts and then schools that belong there. For the record I hadn't had implemented similar structure so no practical experience.
    – Rarst
    May 12, 2011 at 18:53
  • @Rarst Hmm, I thought of that but didn't figure out how to get term parents. Any idea?
    – Mamouneyya
    May 15, 2011 at 14:33

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.