I am using an EntityFieldQuery to return an array of taxonomy terms matching a provided custom field value. Using the example given in this question,this question, I wrote a function that accepts the vocabulary, field name, and field value as arguments and returns an array of matching terms. That works perfectly, but what I really want to get back is just the integer values corresponding to the matching terms, not the array of terms.
The problem is, the data structure that's being returned looks like this:
Array
(
[6] => stdClass Object
(
[tid] => 6
[vocabulary_machine_name] => features_of_interest
)
)
for one item, and for another:
Array
(
[79] => stdClass Object
(
[tid] => 79
[vocabulary_machine_name] => features_of_interest
)
)
Because of this, I can't see how to isolate the [tid] value (6 or 79 in the examples). I'd like to be able to say
$int_tid = $terms[XXX]['tid'];
but I can't get my head around whatever syntax is needed.
I've pasted my function below in case it helps. Ideally I would like to loop through the array of items, isolate each term ID value as an integer, and push it onto an array which the function would then return.
function get_tids_from_custom_field($vocabulary, $field, $value) {
$vocab_machine_name = taxonomy_vocabulary_machine_name_load($vocabulary);
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'taxonomy_term')
->entityCondition('bundle', $vocabulary)
->propertyCondition('vid', $vocab_machine_name->vid)
->fieldCondition($field, 'value', $value, '=');
$terms = $query->execute();
$int_ids = array();
foreach ($terms as $term) {
dpm($term);
array_push($int_ids, $term);
}
return $int_ids;
}