Codex tools: Log in
Languages: English • 日本語 • (Add your language)
Contents |
This function is useful if you wish to access a custom field that is not unique, i.e. has more than 1 value associated with it. Otherwise, you might wish to look at get_post_meta().
Returns an array containing all the values of the custom fields with a particular key ($key) of a post with ID $post_id (defaults to the current post if unspecified).
Returns nothing if no such key exists, or none is entered.
See also get_post_custom() and get_post_custom_keys().
<?php get_post_custom_values($key, $post_id); ?>
Let's assume the current post has 3 values associated with the (custom) field my_key.
You could show them through:
<?php
$mykey_values = get_post_custom_values('my_key');
foreach ( $mykey_values as $key => $value ) {
echo "$key => $value ('my_key')<br />";
}
?>
0 => First value ('my_key')
1 => Second value ('my_key')
2 => Third value ('my_key')
get_post_custom_values() is located in wp-includes/post.php.
Custom Fields: the_meta(), get_post_meta(), add_post_meta(), update_post_meta(), delete_post_meta(), get_post_custom(), get_post_custom_values(), get_post_custom_keys() (See Also: post_meta Function Examples)