mixed An array of values.
False for an invalid $post_id (non-numeric, zero, or negative value).
An empty string if a valid but non-existing post ID is passed.
Default Usage
Use the following example to set a variable ($custom_fields) as a multidimensional array containing all custom fields of the current post.
<?php $custom_fields = get_post_custom(); ?>
Retrieving data from the array
The following example will retrieve all custom field values with the key my_custom_field from post ID 72 (assuming there are three custom fields with this key, and the values are “dogs”, “47” and “This is another value”).
Note: not only does the function return a multi-dimensional array (ie: always be prepared to deal with an array of arrays, even if expecting array of single values), but it also returns serialized values of any arrays stored as meta values. If you expect that possibly an array may be stored as a metavalue, then be prepared to maybe_unserialize.
You must log in before being able to contribute a note or feedback.
Default Usage
Use the following example to set a variable ($custom_fields) as a multidimensional array containing all custom fields of the current post.
Retrieving data from the array
The following example will retrieve all custom field values with the key my_custom_field from post ID 72 (assuming there are three custom fields with this key, and the values are “dogs”, “47” and “This is another value”).
0 => dogs
1 => 47
2 => This is another value
Note: not only does the function return a multi-dimensional array (ie: always be prepared to deal with an array of arrays, even if expecting array of single values), but it also returns serialized values of any arrays stored as meta values. If you expect that possibly an array may be stored as a metavalue, then be prepared to maybe_unserialize.