16

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

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

任何帮助将不胜感激!

4

3 回答 3

24

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

$query = new EntityFieldQuery();
$query->fieldOrderBy('field_name_of_field', 'value', 'DESC');
于 2012-10-25T08:16:23.130 回答
21

您可能正在寻找propertyOrderBy

$query = new EntityFieldQuery();
$query->propertyOrderBy('changed', 'DESC');
于 2013-02-06T22:01:46.580 回答
0

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

$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
                  ->entityCondition('bundle', 'your_content_type')
                  ->propertyCondition('status', 1)
                  ->propertyOrderBy('created', 'DESC');
于 2017-07-27T14:12:42.567 回答