【问题标题】:Drupal - Query to count all nodes of content_type "A" in which field_b is "X"Drupal - 查询计算内容类型为“A”的所有节点,其中 field_b 为“X”
【发布时间】:2015-03-06 04:09:06
【问题描述】:

我需要查询一个 drupal 站点。最初我只需要计算内容类型的节点数:

$query = "SELECT COUNT(*) amount FROM {node} n WHERE n.type ='A'";
$result = db_query($query)->fetch();
return $result->amount;

现在我需要它,但仅适用于 field_b 等于“X”的节点。我该怎么做?

I tried EntityFieldQuery without sucess:

$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'A')
  ->fieldCondition('field_b', 'value', 'X');

$results = $query->execute();
return $results->amount;

有什么帮助吗?

【问题讨论】:

    标签: sql drupal drupal-7 entityreference


    【解决方案1】:

    您可以将查询设置为仅使用计数查询:

    $count = $query->count()->execute();
    

    【讨论】:

    • 谢谢迈克! fieldCondition 是错误的,但我也解决了。
    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多