0

I want to display content based on term ids using below method.If I include the below code in for loop it works but thats not appropriate way to call loop for each index value.Here $all_children[] contains term ids. Can anyone please tell me what is wrong with below code , or any suggestions?

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'escorts_product');
$query->propertyCondition('status', 1);
for($i=0;$i<=20;$i++)
  {
   $query->fieldCondition('field_product_sub_cat', 'tid', $all_children[$i],'=');
  }
$result = $query->execute();
if (isset($result['node']))
  {
    print "nomeer";
    $nids =  array_keys($result['node']);
    nodes = node_load(array_keys($result['node'])); 
    if ((node_load($nids, NULL, TRUE)))
      {
       foreach($nids as $nid)
         {
          //content
         }
      }  
   }
0

I think this is the right way because it works for me. Error was in below line.

$query->fieldCondition('field_product_sub_cat', 'tid', $all_children[$i],'=');

Correct way to compare with array is:

 $query->fieldCondition('field_product_sub_cat', 'tid', array("$your_array_variable"));

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.