Skip to content

Instantly share code, notes, and snippets.

@shrop
Last active December 14, 2015 14:58
Show Gist options
  • Save shrop/5104361 to your computer and use it in GitHub Desktop.
Save shrop/5104361 to your computer and use it in GitHub Desktop.
EntityFieldQuery() example to return all published articles
<?php
/**
* @file
* EntityFieldQuery demo.
*/
$query = new EntityFieldQuery();
// Return all articles that are published.
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->execute();
// Print all nids to dd().
if (isset($result['node'])) {
foreach (array_keys($result['node']) as $nid) {
dd($nid);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment