Last active
August 29, 2015 14:12
-
-
Save ranelpadon/ffac96928570ca584422 to your computer and use it in GitHub Desktop.
Get the node type of the current node using EntityFieldQuery (EFQ) API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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