Created
February 12, 2014 15:18
-
-
Save ChrisLTD/8957379 to your computer and use it in GitHub Desktop.
Drupal 7 Get nodes by type, taxonomy term, and sort by custom field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = db_select('node', 'n'); | |
$query->join('field_data_field_vertical', 'v', 'v.entity_id=n.nid'); | |
$query->join('field_data_field_date', 'd', 'd.entity_id=n.nid'); | |
$query | |
->fields('n', array('nid', 'title', 'created')) | |
->fields('d', array('field_date_value')) | |
->condition('v.field_vertical_tid', 1) | |
->condition('n.status', 1) | |
->condition('n.type', 'event') | |
->orderBy('d.field_date_value', 'DESC') | |
/* ->orderBy('created', 'DESC') */ | |
->range(0,3); //LIMIT to 2 records | |
$result = $query->execute(); | |
while( $record = $result->fetchAssoc() ) { | |
echo "<pre>" . print_r( $record , true) . "</pre>"; | |
echo url('node/' . $record['nid']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment