Skip to content

Instantly share code, notes, and snippets.

@ranelpadon
Last active August 29, 2015 14:12
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 ranelpadon/ffac96928570ca584422 to your computer and use it in GitHub Desktop.
Save ranelpadon/ffac96928570ca584422 to your computer and use it in GitHub Desktop.
Get the node type of the current node using EntityFieldQuery (EFQ) API.
<?php
// Get the node id from the current page's URL.
$nid = arg(1);
// Create a new EFQ object.
$query = new EntityFieldQuery();
// Select the node entity with the target node id.
$query->entityCondition('entity_type', 'node');
$query->entityCondition('entity_id', $nid );
$result = $query->execute();
// Get the node type.
// If you will inspect the content of $result['node'][$nid],
// it will contain 3 information only: its node type, node id, and revision id,
// which are much leaner than node_load().
$node_type = $result['node'][$nid]->type;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment