1

How can I get a list of all the fields that have been attached to a taxonomy vocabulary?

I have created 2 new fields using admin/structure/taxonomy/[machinename]/fields now I need to get all the fields and use them on a settings form. I have the vocabulary machine name, but how do I retrieve all fields created?

2

You can use field_info_instances() which:

Retrieves information about field instances.

In the case of taxonomy terms the code would look like this:

$instances = field_info_instances('taxonomy_term', $vocab_machine_name);

The $instances array will contain (amongst other things) the machine names of all the fields attached to the term, if you want further information about any or all of those fields you can run the names through field_info_field().

I think the file that function lives in is included by default but if not just add this before you call it:

module_load_include('inc', 'field', 'field.info');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.