2015-03-13 70 views
0

這裏我想從我的內容類型product_categories中獲取匹配的子項id的nid。我使用了下面的代碼。在drupal中獲取nid

$query = new EntityFieldQuery(); 
$query->entityCondition('entity_type', 'node'); 
$query->entityCondition('bundle', 'product_categories'); 
$query->propertyCondition('status', 1); 
$query->fieldCondition('field_product_sub_cat', 'tid', $child->tid, '='); 
$result = $query->execute(); 

我執行上面的查詢,現在顯示正確results.But我想取NID,我用下面的代碼,但它不工作。

$childnid = $result->nid; //Area to explore 
//print "<pre>"; print_r ((int)$childnid); 
print $childnid; 

有人能幫我嗎?

+0

改編

if (isset($result['node'])) { $nids = array_keys($result['node']); } 

您需要選擇查詢,如果'nid'你想使用它。目前您只選擇'entity_type'&'節點'。 – Darren 2015-03-13 07:06:21

回答

0

你快到了。執行查詢之後,生成的實體標識以數組形式存儲,該數組本身位於由實體類型(本例中爲「節點」)鍵入的數組內。要檢查,並得到節點ID(S)的陣列,直接用這個你叫的execute()後:從How to use EntityFieldQuery