Dropdown Menu of All Terms in Custom Taxonomy – WordPress

Built-in to WordPress is a nifty function, wp_dropdown_categories, that is supposed to list all your categories in a drop-down menu and, with the right script, link directly to them. It even has an argument for using it with a custom taxonomy. The only thing is, it doesn’t work. It doesn’t produce the appropriate link. It appears to produce a link like /?cat=# which you would assume would work if you weren’t using pretty permalinks. Only it doesn’t . It never works. I’m not sure why this hasn’t been addressed but it is a serious hole in this function.

Alternately, you can create just a list of parent-level terms with links to their pages and no dropdown menu,

So how do we make this work?  After some digging online, I found this script. It was originally developed here years ago, but it was brought back to life here. And it works brilliantly. Here’s the code:

Tired of dealing with your slow WordPress website? Email me at brian@pagecrafter.com and mention the code #FreeHosting10 for two free months of lightning-fast WordPress hosting. We will even migrate you for free!

To make this work for your taxonomy, replace “custom-tax” near the top with the name of your custom taxonomy. Then near the bottom, replace “/category/” with the slug for your custom taxonomy. In my case, I replaced it with “/location/”. Drop this right in, and it should work great!You can adjust the $args by putting them in get_categories(). You can view the WordPress Codex on that function here. Simple stuff!I personally spent many many hours trying to make the regular wp_dropdown_categories working for me, but to no avail. Finding this script made my life so much easier, and hopefully it will do the same for you.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.