Skip to content

Instantly share code, notes, and snippets.

@danreb
Created June 20, 2013 00:20
Show Gist options
  • Save danreb/5819320 to your computer and use it in GitHub Desktop.
Save danreb/5819320 to your computer and use it in GitHub Desktop.
Using EntityFieldQuery() to get node type and display it on custom php page in Drupal 7
<?php
// Get path of Drupal install.
$drupal_path = $_SERVER['DOCUMENT_ROOT'];
// Defines our path to the Drupal install
define('DRUPAL_ROOT', $drupal_path);
// We need to load the bootstrap.inc file so we can have access to the drupal_bootsrap() function
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
// Bootstrap Drupal at the phase that you need
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Our custom page now has access to Drupal functions such as node_load() and db_query() and entity field query
$query = new EntityFieldQuery();
$entities = $query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'package')
->propertyOrderBy('created', 'ASC')
->propertyCondition('status', 1)
->range(0,10)
->addMetaData('account', user_load(1));
$result = $query->execute();
$nids = array_keys($result['node']);
$nodes = node_load_multiple($nids);
$output = node_view_multiple($nodes);
?>
<!DOCTYPE html>
<html>
<head><title> Custom Page</title>
</head>
<body>
<?php print render($output); ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment