If you dump the code into functions.php
, then the custom taxonomy hasn’t been registered, because it isn’t recommend to register custom taxonomies earlier than the init
hook.
Running the code within the template hierarchy files should work, because it’s later than init
.
If you want to run it within the functions.php
file, make sure to hook it accordingly.