fetch the taxonomy terms inside a particular vocabulary

$taxonomyQuery = new EntityFieldQuery();
$taxonomyTerms = $taxonomyQuery->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('vid', 2) //change 2 to any vocabulary ID
->propertyOrderBy('weight')
->execute();
foreach($taxonomyTerms['taxonomy_term'] as $term) {
$relevantTerms[] = $term->tid;
}

get a list of nodes that match your criteria

$nodeQuery = new EntityFieldQuery();
$entities = $nodeQuery->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'article') // to target content_type
  ->propertyCondition('uid', 1)
  ->propertyCondition('status', 1)
  ->fieldCondition('field_catetory', 'tid', 2)
  ->execute();
if($entities) foreach($entities['node'] as $entity){
  $node = node_load($entity->nid);
  print $node->title;
}

fetch user with profile2 entity

$entityQuery = new EntityFieldQuery();
$entities = $entityQuery->entityCondition('entity_type', 'profile2')
    ->entityCondition('bundle', 'merchant')
    ->fieldCondition('field_user_name', 'value', $string)
    ->execute();
if($entities) foreach($entities['profile2'] as $entity){
    $profile = profile2_load($entity->pid);
    print $profile->uid;
}

entity_metadata_wrapper

$node = node_load(9999);
$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->field_body->value(); // return text type
$node_wrapper->field_term->value()->name; // return term object
$node_wrapper->field_link->value()['url']; // return array
$node_wrapper->field_images[0]->value();

猫之良品
2.5k 声望139 粉丝

资深Drupal, magento与Joomla


引用和评论

0 条评论