Created
October 25, 2013 07:52
-
-
Save sebcunin/7150966 to your computer and use it in GitHub Desktop.
EntityFieldQuery is a class, new to Drupal 7, that allows retrieval of a set of entities based on specified conditions. It allows finding of entities based on entity properties, field values, and other generic entity metadata. The syntax is really compact and easy to follow, as well. And, best of all, it's core Drupal; no additional modules are …
This file contains 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 = new EntityFieldQuery(); | |
$query->entityCondition('entity_type', 'node') | |
->entityCondition('bundle', 'article') | |
->propertyCondition('status', 1) | |
->fieldCondition('field_news_types', 'value', 'spotlight', '=') | |
->fieldCondition('field_photo', 'fid', 'NULL', '!=') | |
->fieldCondition('field_faculty_tag', 'tid', $value) | |
->fieldCondition('field_news_publishdate', 'value', $year. '%', 'like') | |
->fieldOrderBy('field_photo', 'fid', 'DESC') | |
->range(0, 10) | |
->addMetaData('account', user_load(1)); // Run the query as user 1. | |
$result = $query->execute(); | |
if (isset($result['node'])) { | |
$news_items_nids = array_keys($result['node']); | |
$news_items = entity_load('node', $news_items_nids); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment