get_post_custom single array

Is there a way to return single values only when I run

get_post_custom($post_id);

it seems that I’m receiving double array, even when there only one value for this meta_key

Related posts

2 comments

  1. this is what I’ve done to achieve this, it will return single dimension array when single results are found, and bi-dimensional array when multiple results are found

    /*
     * Get post custom Single (in functions.php)
     */
    
    function get_post_custom_single($post_id) {
      $metas = get_post_custom($post_id);
    
      foreach($metas as $key => $value) {
        if(sizeof($value) == 1) {
          $metas[$key] = $value[0];
        }
      }
      return $metas;
    }
    
  2. // change the meta key and note the last true
    get_post_meta($post_id, 'your_meta_key_goes_here', true); 
    

    See Codex for get_post_meta

    If you look at get_post_custom in the Codex you will read:

    Returns a multidimensional array with all custom fields of a
    particular post or page

Comments are closed.