1

I have added a vocabulary as Sites with machine name as sites. I have added two custom fields in this vocabulary as :

1) URL 2) Status 0 or 1

I need to make a dropdown of all terms with status 1 something like.

get term.name from term join vocabulary on vid where vocabulary.machine_name = sites and term.status = 1

$v =  taxonomy_vocabulary_machine_name_load('sites');

$t = taxonomy_get_tree($v->vid);

How do I get an array of enabled terms in the 'sites' vocabulary?

1 Answer 1

3

Yes, entity_load can be used, but you have to retrieve entity ids yourself:

$terms = array();

$v = taxonomy_vocabulary_machine_name_load('sites');
$query = new EntityFieldQuery();
$result = $query
  ->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', $v->vid)
  ->fieldCondition('field_status', 'value', 1) // If your field name is 'field_status'
  ->execute();

if (!empty($result['taxonomy_term'])) {
  $terms = entity_load('taxonomy_term', array_keys($result['taxonomy_term']));
}

// dpm($terms);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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