如何获取Drupal中节点列表的特定字段?

时间:2015-03-08 12:32:17

标签: drupal drupal-7

我在Drupal中有以下代码来获取符合特定条件的节点列表:

function get_failgames($form, &$form_state) {  
        $query = new EntityFieldQuery();

  $query
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'game_results')
    ->propertyCondition('status', 1)
                ->fieldCondition('field_division', 'tid', (array) $form_state['values']['division'])
                ->fieldCondition('field_ft_home_team_goals', 'value', 5, '=')
    ->addMetaData('account', user_load(1)); // Run the query as user 1.

  $result = $query->execute();

        dpm($result);
}

现在我想获得这些节点的一个或多个字段。我该怎么做?加载每个节点?

谢谢!

1 个答案:

答案 0 :(得分:2)

您需要使用node_load_multiple()功能&将array_keys($result['node'])作为参数传递给同一个人。请检查以下示例代码:

function get_failgames($form, &$form_state) {  
        $query = new EntityFieldQuery();

        $query
        ->entityCondition('entity_type', 'node')
        ->entityCondition('bundle', 'game_results')
        ->propertyCondition('status', 1)
        ->fieldCondition('field_division', 'tid', (array) $form_state['values']['division'])
        ->fieldCondition('field_ft_home_team_goals', 'value', 5, '=')
        ->addMetaData('account', user_load(1)); // Run the query as user 1.

        $result = $query->execute();
        $nodes = node_load_multiple(array_keys($result['node']));
        dpm($result);
        dpm($nodes);
}