Thanks for the report. Before we look into the source code, can you address these issues with your code?
1. Have you validated the data of $terms
2. Does your loop run correctly. Can you show this?
3. What is $taxonomyName
4. I think $term->term_taxonomy_id; should be $term->term_id;
5. Have you tested $field_query
6. echo (the_field is not needed, the_field will already echo the value.