drupal-7 - EntityFieldQuery 多个备选条件

标签 drupal-7

是否有更优化和更短的方法来获得特定条件的节点?

$query = new EntityFieldQuery;
$result = $query
  ->entityCondition('entity_type', 'node')
  ->propertyCondition('type', $node_type)
  ->propertyCondition('title', $title)
  ->fieldCondition('field_number', 'value', '1', '=');
  ->propertyCondition('status', 1, '=')
  ->execute();

// $result['node'] contains a list of nids where the title matches
if (!empty($result['node']) {
  // You could use node_load_multiple() instead of entity_load() for nodes
  $nodes = entity_load('node', array_keys($result['node']));
}

$query_two = new EntityFieldQuery;
$result_two = $query_two
  ->entityCondition('entity_type', 'node')
  ->propertyCondition('type', $node_type)
  ->propertyCondition('title', $title)
  ->fieldCondition('field_number', 'value', '2', '=');
  ->propertyCondition('status', 1, '=')
  ->execute();

// $result_two['node'] contains a list of nids where the title matches
if (!empty($result_two['node']) {
  // You could use node_load_multiple() instead of entity_load() for nodes
  $nodes_two = entity_load('node', array_keys($result_two['node']));
}

最佳答案

那么,你当然可以使用 ->fieldCondition('field_number', 'value', array(1, 2)) ,但除此之外,我不知道(我写了 EntityFieldQuery )。即使您将其重写为仅用于 SQL 存储的查询,也不会简单得多。

您不需要指定 =作为运算符,您无需指定 IN或者,它们是标量/数组值的默认值。

关于drupal-7 - EntityFieldQuery 多个备选条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6017317/

相关文章:

php - 能够在 print_r() 的输出中看到一个变量,但不确定如何在代码中访问它

drupal - 如何在预告模式下显示一张图像,而在完整内容下显示多张图像?

drupal - 什么是 drupal 中的伪 Hook ?

drupal - 如何在 Drupal 7 中将 block 插入节点或模板?

php - Xampp 服务器 MySQL 错误? MySQL 数据库的状态 - DEACTIVATED

Drupal 7 - 在#link 表单类型条目中添加 HTML?

php - Drupal 7 db_update - 检查错误

php - 我如何将新的键值对推送到数组 php?

drupal-7 - Drupal 7 Forms API - AJAX Forms 错误 : An illegal choice has been detected. 请联系站点管理员