Althought there are a lot of examples of making a query in Drupal 7 filtering on multiple taxonomy terms in an exclusive way (AND), we found that there are almost no examples or documentation to find nodes that have one of N taxonomy terms. I will show how to EntityFieldQuery filter by taxonomy terms inclusive.

Querying nodes by taxonomy terms (AND)

$tids = [];
$query = new EntityFieldQuery();
$query->entityCondition('entity_type','node')
->entityCondition('bundle','article')
->propertyCondition('language',$language->language);
foreach($tids as $tid){
$query->fieldCondition('field_tags','tid',[$term->tid]);
}
$results = $query->execute();

Queryng nodes by taxonomy terms (OR)

global $language;
$query = new EntityFieldQuery();
$query->entityCondition('entity_type','node')
->entityCondition('bundle','article')
->propertyCondition('language',$language->language);
$query->fieldCondition('field_tags','tid',$tids);
$results = $query->execute();

Hope this helps anybody looking for this and future me.

Dejar respuesta

Please enter your comment!
Please enter your name here