Skip to content

Instantly share code, notes, and snippets.

@renebakx
Created March 7, 2014 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renebakx/9410575 to your computer and use it in GitHub Desktop.
Save renebakx/9410575 to your computer and use it in GitHub Desktop.
EntityFieldQuery
<?php
// build from drupal_get_query_parameters();
$filterQuery = array('news', 'blog', 'article');
// build query
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->propertyCondition('type', 'page');
$query->propertyCondition('status', 1);
$query->fieldCondition('field_page_type', 'value', $filterQuery, 'in');
$query->propertyOrderBy('title', 'ASC');
$results = $query->execute();
// build renderable items
$pages = array();
if (isset($results['node'])) {
$nodes = entity_load('node', array_keys($results['node']));
$pages = entity_view('node', $nodes, 'teaser');
}
return $pages;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment