WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post custom values

Description

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().

Usage

 <?php get_post_custom_values($key$post_id); ?> 

Parameters

$key
(string) (required) The key whose values you want returned.
Default: None
$post_id
(integer) (optional) The post ID whose custom fields will be retrieved.
Default: Current post

Examples

Default Usage

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' )

Source File

get_post_custom_values() is located in wp-includes/post.php.

Related

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)

See also index of Function Reference and index of Template Tags.