1

I'm building a project where i've decided to heavily use Drupal items (nodes, taxonomy, views) but i find hard to retrieve data in a simple way.

I've defined a taxonomy vocabulary with custom fields that are references to other vocabulary terms.

For example i have a book_author vocabulary and books vocabulary and need to get all the books written by a certain author tid.

Are there apis that i can use with a single call or do i have to use Sql queries on taxonomy_* field_data_* tables?

1

The EntityFieldQuery class is the normal tool fot this sort of task. Have a look at the docs for more information, but this is a basic example based around what you've mentioned in your question:

$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', $vocab_id_of_terms_you_want_to_select)
  ->fieldCondition('field_author', 'tid', $the_author_tid);

$results = $query->execute();

$found_terms = taxonomy_term_load_multiple(array_keys($results['taxonomy_term']));
  • Great, really what i was looking for. Thanks a lot !! – Cris Sep 7 '12 at 10:10

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.