Drupal 7 - entityFieldQuery Order

时间:2012-10-24 09:33:21

标签: drupal-7

早上,我试图获得一组最新的节点类型,但似乎无法弄清楚如何按日期订购它们。到目前为止,我的功能是:

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

任何帮助都会非常感激!

3 个答案:

答案 0 :(得分:23)

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

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

答案 1 :(得分:20)

您可能正在寻找propertyOrderBy

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

答案 2 :(得分:0)

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

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