Determine if an Entity is Published Without Loading the Node

Last modified: 
Friday, December 4th, 2015
Topics: 
Drupal7

A method to quickly determine if a Drupal entity is published without loading the whole node.

/**
 * Determines if an entity is published without loading the whole node.
 *
 * @param $nid
 *  The nid of the entity to check.
 * @return
 *  Returns 1 if the node is published, 0 if not.
 */
protected function isPublished($nid) {
  $sql = "SELECT status FROM {node} WHERE nid = :nid LIMIT 1";
  return (db_query($sql, array(':nid' => $nid))->fetchField()) ? TRUE : FALSE;
}


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.