【问题标题】:Drupal 7 - entityFieldQuery OrderDrupal 7 - entityFieldQuery 订单
【发布时间】:2012-10-14 07:56:35
【问题描述】:

早上好,我正在尝试获取一组最新的节点类型,但似乎无法弄清楚如何按日期对它们进行排序。到目前为止,这是我的功能:

function latest_nodes($type, $limit = 15, $offset = 0) {
    $query = new EntityFieldQuery();
    $tmp = $query->entityCondition('entity_type', 'node');
    if( is_string( $type ) )
        $tmp->entityCondition('bundle', $type);
    elseif( is_array( $type ) )
        $tmp->entityCondition('bundle', $type, 'IN');
    $tmp->range($offset, $limit);
    $results = $tmp->execute();
    return node_load_multiple(array_keys($results['node']));
}

任何帮助将不胜感激!

【问题讨论】:

    标签: drupal-7


    【解决方案1】:

    检索您可以使用的最新帖子

    $query = new EntityFieldQuery();
    $entities = $query->entityCondition('entity_type', 'node')
                      ->entityCondition('bundle', 'your_content_type')
                      ->propertyCondition('status', 1)
                      ->propertyOrderBy('created', 'DESC');
    

    【讨论】:

      【解决方案2】:

      您可能正在寻找propertyOrderBy

      $query = new EntityFieldQuery();
      $query->propertyOrderBy('changed', 'DESC');
      

      【讨论】:

      • 使用->range(0,15); 限制为15个节点。
      【解决方案3】:

      您正在寻找fieldOrderBy() 成员函数,例如

      $query = new EntityFieldQuery();
      $query->fieldOrderBy('field_name_of_field', 'value', 'DESC');
      

      【讨论】:

      • 哇。第二个参数实际上是value。这出人意料地难以找到,而且似乎是最常见的用例。
      • @JonSurrell 从技术上讲,第二个参数是列名,在大多数情况下默认为 value
      猜你喜欢
      • 2014-04-07
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      相关资源
      最近更新 更多