Drupal 7 - entityFieldQuery Order - программирование
Подтвердить что ты не робот

Drupal 7 - entityFieldQuery Order

Утро, я пытаюсь получить набор из последних node типов, но не могу понять, как упорядочить их по дате. До сих пор моя функция:

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

любая помощь была бы очень оценена!

4b9b3361

Ответ 1

Вы ищете функцию fieldOrderBy(), например

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

Ответ 2

Возможно, вы ищете propertyOrderBy

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

Ответ 3

, чтобы получить последнее сообщение, которое вы можете использовать

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