使用entityfieldquery获取nids

时间:2015-04-11 14:03:33

标签: drupal-7

我想得到所有的nids,但我无法得到它们。以下是我的摘录。

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'product');
$query->propertyCondition('status', 1);
$query->fieldCondition('field_product_sub_cat', 'tid',array($leaf_nodes));
$query->range(0, 10);
$result = $query->execute();
if (isset($result['node']))
{
  $product_childnid = array_keys($result['node']);
}

以下是我的结果:更新

Array
(
[node] => Array
    (
        [78] => stdClass Object
            (
                [nid] => 78
                [vid] => 78
                [type] => product
            )

        [80] => stdClass Object
            (
                [nid] => 80
                [vid] => 80
                [type] => product
            )

        [82] => stdClass Object
            (
                [nid] => 82
                [vid] => 82
                [type] => product
            )

        [84] => stdClass Object
            (
                [nid] => 84
                [vid] => 84
                [type] => product
            )

        [86] => stdClass Object
            (
                [nid] => 86
                [vid] => 86
                [type] => product
            )

        [88] => stdClass Object
            (
                [nid] => 88
                [vid] => 88
                [type] => product
            )

        [90] => stdClass Object
            (
                [nid] => 90
                [vid] => 90
                [type] => product
            )

        [92] => stdClass Object
            (
                [nid] => 92
                [vid] => 92
                [type] => product
            )

        [94] => stdClass Object
            (
                [nid] => 94
                [vid] => 94
                [type] => product
            )

        [100] => stdClass Object
            (
                [nid] => 100
                [vid] => 100
                [type] => product
              )
          )
  )

然后下面的代码也为我提供了所有路径,

$paths = array();
if (isset($result['node']))
{
 foreach($result['node'] as $key => $node) 
 {
 $paths[$node->nid] = drupal_get_path_alias("node/$node->nid");
 }
}

现在接下来的问题是如何在我的锚标记中表示这些路径?因为它们都在一个数组中.Below是路径别名的数组结构:

Array
(
 [78] => equivalent-fireman-glove-details
 [80] => toughguard®-2
 [82] => toughguard®-3
 [84] => toughguard-®sizzler®
 [86] => tough-guard-®
 [88] => kevlar®-double-glove
 [90] => nomex®-industrial-coverall
 [92] => tough-guard®-clinker®-0
 [94] => lab-coats-sa-nlc
)

及以下是与上述路径链接的数组结构数据:

Array
(
 [0] => 71
 [1] => 73
 [2] => 81
 [3] => 83
 [4] => 85
 [5] => 87
 [6] => 89
 [7] => 91
 [8] => 93
) 

1 个答案:

答案 0 :(得分:0)

试试这个:

$query->fieldCondition('field_product_sub_cat', 'tid',array($leaf_nodes),'IN');

这样查询比较值与数组。