I have a taxonomy field with (usually multiple) terms attached (article_secondary_tags). In my fieldCondition I want to test that all of the terms are NOT IN the exclude array ($exclude_terms). If ANY of the terms are in the array, that node should be excluded from the result. Here is what I have so far.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('article_primary_tag', 'tid', $exclude_terms, 'NOT IN')
->fieldCondition('article_secondary_tags', 'tid', $exclude_terms, 'NOT IN')
->fieldCondition('aw_article_primary_tag', 'tid', $landingterms)
->propertyOrderBy('created', 'DESC')
->range(0, $itemsneeded);
$result = $query->execute();
The Primary tag field is excluding the node properly, but this field is a single taxonomy term. Also, if there is only one term referenced in the secondary tags, and it is in exclude_terms, it will work properly. The real problem is getting it to exclude the node from the queue if just one of the several secondary tags is in the $exclude_terms array. Almost like an "ALL NOT IN" operator would be needed.
Note: I'm using the primary tag to pull articles in (if that term id is in $landingterms). But they should not be included if they have a secondary tag that is to be excluded.
Thanks in advance for any hints and answers. Can't figure this one out!
Cheers
When you pass an array the operator becomes an OR. It's not nice but you could do a foreach.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('article_primary_tag', 'tid', $exclude_terms, 'NOT IN')
->fieldCondition('aw_article_primary_tag', 'tid', $landingterms)
->propertyOrderBy('created', 'DESC')
->range(0, $itemsneeded);
foreach ($exclude_terms as $exclude_term) {
$query->fieldCondition('article_secondary_tags', 'tid', $exclude_term, 'NOT IN');
}
$result = $query->execute();