0 ) { $this->get_viewing( $id ); } } /** * Gets a viewing from the database. * * @access public * @param int $id (default: 0) * @return bool */ public function get_viewing( $id = 0 ) { if ( ! $id ) { return false; } if ( $result = get_post( $id ) ) { $this->populate( $result ); return true; } return false; } /** * __isset function. * * @access public * @param mixed $key * @return bool */ public function __isset( $key ) { if ( ! $this->id ) { return false; } return metadata_exists( 'post', $this->id, '_' . $key ); } /** * __get function. * * @access public * @param mixed $key * @return mixed */ public function __get( $key ) { // Get values or default if not set $value = get_post_meta( $this->id, $key, true ); if ($value == '') { $value = get_post_meta( $this->id, '_' . $key, true ); } return $value; } /** * Populates a viewing from the loaded post data. * * @access public * @param mixed $result * @return void */ public function populate( $result ) { // Standard post data $this->id = $result->ID; $this->post_title = $result->post_title; $this->post_status = $result->post_status; } }