I do not know of you’ve figured this out yet or not, but I don’t see anything wrong in your add_local_field() code. The only thing I can come up with is that your query is not returning what you think it should be returning.
I would try using wp_get_object_terms() rather than a custom query. https://developer.wordpress.org/reference/functions/wp_get_object_terms/