Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 - entityFieldQuery Order

Tags:

drupal-7

Morning, im trying to get a set of latest node types but cant seem to figure out how to order them by date. Heres my function so far:

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

any help would be muchly appreciated!

like image 788
Luke Snowden Avatar asked Oct 24 '12 09:10

Luke Snowden


1 Answers

You're looking for the fieldOrderBy() member function, e.g.

$query = new EntityFieldQuery();
$query->fieldOrderBy('field_name_of_field', 'value', 'DESC');
like image 61
Clive Avatar answered Sep 19 '22 19:09

Clive