简体   繁体   English

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

[英]How to get specific fields of a list of nodes in Drupal?

I have the following code in Drupal to get the list of nodes that match certain conditions: 我在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);
}

Now I want to get one or more fields of those nodes. 现在,我想获得这些节点的一个或多个字段。 How should I do this? 我应该怎么做? Load each single node? 加载每个单个节点?

Thanks! 谢谢!

You need to use node_load_multiple() function & pass array_keys($result['node']) as an argument to the same. 您需要使用node_load_multiple()函数并传递array_keys($result['node'])作为该参数的参数。 Please check sample code below: 请检查以下示例代码:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM