Get CCK Fields Referenced Values

There may come a time when you need to retrieve an array of the values that are stored in a CCK node reference or user reference field. When that time comes, hopefully this function will be of some help. I use it a lot in many of my custom modules.

<?php
/**
 * Get Referenced Field values
 * @param $field_array array An array of referenced items (nid or uid)
 * @return array An array of values
 */
function get_referenced_field_values($field_array,$key = 'nid'){
   
$values = array();
    foreach(
$field_array as $field){
        if(
$field[$key])
           
$values[] = $field[$key];
    }
    return
$values;
}
?>
Categories: 
Get CCK Fields Referenced Values | Gerrit Brands

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /homepages/29/d196880538/htdocs/drupal7/includes/common.inc:2681) in drupal_send_headers() (line 1212 of /homepages/29/d196880538/htdocs/drupal7/includes/bootstrap.inc).
  • PDOException: SQLSTATE[42000]: Syntax error or access violation: 1142 INSERT command denied to user 'dbo354826752'@'74.208.16.6' for table 'watchdog': INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => cron [:db_insert_placeholder_2] => Attempting to re-run cron while it is already running. [:db_insert_placeholder_3] => a:0:{} [:db_insert_placeholder_4] => 4 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://gerritbrands.com/blog/get-cck-fields-referenced-values [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => 54.166.245.10 [:db_insert_placeholder_9] => 1508377278 ) in dblog_watchdog() (line 154 of /homepages/29/d196880538/htdocs/drupal7/modules/dblog/dblog.module).

Error

The website encountered an unexpected error. Please try again later.