0

我是 Drupal 7 的新手。

我正在尝试加载其类型和标题作为参数传递的特定节点的数据:

$param = array(
'type' => 'media',
'title' => 'Home Logo Bottom Image',
'status' => 1,
);

// Getting node details
$result = node_load($param);
echo "<pre>";
print_r($result);

stdClass Object
(
    [vid] => 1
    [uid] => 1
    [title] => Career Tip 1
    [log] => 
    [status] => 1
    [comment] => 2
    [promote] => 1
    [sticky] => 0
    [nid] => 1
    [type] => career_tips
    [language] => und
    [created] => 1377871907
    [changed] => 1377871907
    [tnid] => 0
    [translate] => 0
    [revision_timestamp] => 1377871907
    [revision_uid] => 1
    [body] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => If you meet a woman doing a STEM job that sounds even remotely interesting to you, see if you can stop by her office for an “informational interview.” At the meeting, ask her every single question you have, even if they seem obvious or silly.
                            [summary] => 
                            [format] => full_html
                            [safe_value] => 
If you meet a woman doing a STEM job that sounds even remotely interesting to you, see if you can stop by her office for an “informational interview.” At the meeting, ask her every single question you have, even if they seem obvious or silly.


                            [safe_summary] => 
                        )

                )

        )

上面代码的输出不正确,因为它显示了其他标题。我在这里缺少什么?

我也想获取同一节点的自定义字段值。那么是否有一个 API 可以返回整个数据?

4

2 回答 2

1

在 drupal 7 中node_load函数的行为发生了变化。传递给 node_load 的第一个参数必须是节点 ID。

使用EntityFieldQuery获取与您的查询匹配的所有节点 ID,然后使用 node_load($nid); 加载节点;

$query = new EntityFieldQuery();
$title = 'Enter the title of the node you want to search for here';
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'career_tips')
  ->propertyCondition('status', 1)
  ->propertyCondition('title', $title);

$result = $query->execute();

if (isset($result['node'])) {
  $node_nids = array_keys($result['node']);
  $items = entity_load('node', $node_nids);
}

// Now $items should contain the nodes.

此外,一旦有了节点对象,您就可以使用EntityMetadataWrapper 方便地提取值。

于 2013-09-05T08:47:37.743 回答
1

您也可以使用 node_load_multiple 函数,但它已被弃用。第二个参数是条件。

$node = current(node_load_multiple(array(), array(
    'title' => 'Home Logo Bottom Image',
)));
于 2013-09-05T09:56:45.723 回答