Skip to content

Instantly share code, notes, and snippets.

@MKorostoff
Last active August 29, 2015 14:16
Show Gist options
  • Save MKorostoff/9ebe273016c9f488170d to your computer and use it in GitHub Desktop.
Save MKorostoff/9ebe273016c9f488170d to your computer and use it in GitHub Desktop.
<?php
function my_module_menu() {
return array(
'mypage' => array(
'page callback' => 'mypage_callback',
'access callback' => TRUE,
)
);
}
function mypage_callback() {
//Instantiate a new query
$query = new EntityFieldQuery();
//Add conditions to the query
$query->entityCondition('entity_type', 'node') //only return nodes (we could also return users, taxonomy terms, or any other drupal entity)
->entityCondition('bundle', 'article') //Only return articles
->propertyCondition('status', NODE_PUBLISHED) //Only return published nodes
->propertyCondition('title', 'K', '>') //only return nodes whose title starts with the letters L through Z.
->propertyOrderBy('title'); //alphabetize
//Run the query
$result = $query->execute();
$nodes = array();
if (!empty($result['node'])) {
foreach ($result['node'] as $nid => $node_metadata) {
//Load all of the nodes we found into a renderable array
$nodes[] = node_view(node_load($nid), 'teaser');
}
}
return $nodes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment