Node load by title

Public

Load a node by title

Get raw version
php
  1. /**
  2.  * Based on http://drupal.stackexchange.com/a/34400
  3.  */
  4.  
  5. /**
  6.  * Helper function; Load node by title
  7.  */
  8. function node_load_by_title($title, $node_type) {
  9. $query = new EntityFieldQuery();
  10. $entities = $query->entityCondition('entity_type', 'node')
  11. ->propertyCondition('type', $node_type)
  12. ->propertyCondition('title', $title)
  13. ->propertyCondition('status', 1)
  14. ->range(0,1)
  15. ->execute();
  16. if(!empty($entities)) {
  17. return node_load(array_shift(array_keys($entities['node'])));
  18. }
  19. }