How to create a list of custom taxonomies in WordPress
Nov 03, 2014 by Micro Themes in TutorialsExpand Text
While developing our Quantum theme we came across a particular problem – how to display a drop list menu of a custom taxonomy. We required this functionality for our private members area, in particular a widget that we were developing to organize client files by year. At first we discovered the get_terms function, which is native to WordPress, but we were unable to populate our list due to the fact that the slugs in the taxonomy were not assigned to anything in particular – which makes total sense if you think about it…if slugs are not assigned to anything why display them? In our case we are using these slugs for filtering purposes so we needed to display them regardless of their relationship status.
It turns out that we were missing a crucial argument needed to retrieve slugs in their empty state (slugs are considered empty to WordPress when they are not assigned to anything) and here is the code to make it work:
$archiveDates = get_terms( 'archive_assignment', array( 'hide_empty' => 0 ) );
As you can see in the code we passed in the hide_empty argument and set its value to 0 (it can also be set to “false” if you prefer). And to further clarify the “archive_assignment” is the name of our custom taxonomy that we created for media file types.
And that’s all there is to it :]