post_custom

The timeline below displays how wordpress function post_custom has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

//
// Post-meta: Custom per-post fields.
//
/**
 * Retrieves post custom meta data field.
 *
 * @since 1.5.0
 *
 * @param string $key Meta data key name.
 * @return array|string|false Array of values, or single value if only one element exists.
 *                            False if the key does not exist.
 */
function post_custom($key = '')
{
    $custom = get_post_custom();
    if (!isset($custom[$key])) {
        return false;
    } elseif (1 === count($custom[$key])) {
        return $custom[$key][0];
    } else {
        return $custom[$key];
    }
}

WordPress Version: 5.5

//
// Post-meta: Custom per-post fields.
//
/**
 * Retrieve post custom meta data field.
 *
 * @since 1.5.0
 *
 * @param string $key Meta data key name.
 * @return array|string|false Array of values, or single value if only one element exists.
 *                            False if the key does not exist.
 */
function post_custom($key = '')
{
    $custom = get_post_custom();
    if (!isset($custom[$key])) {
        return false;
    } elseif (1 === count($custom[$key])) {
        return $custom[$key][0];
    } else {
        return $custom[$key];
    }
}

WordPress Version: 5.4

//
// Post-meta: Custom per-post fields.
//
/**
 * Retrieve post custom meta data field.
 *
 * @since 1.5.0
 *
 * @param string $key Meta data key name.
 * @return array|string|false Array of values, or single value if only one element exists.
 *                            False if the key does not exist.
 */
function post_custom($key = '')
{
    $custom = get_post_custom();
    if (!isset($custom[$key])) {
        return false;
    } elseif (1 == count($custom[$key])) {
        return $custom[$key][0];
    } else {
        return $custom[$key];
    }
}

WordPress Version: 4.3

//
// Post-meta: Custom per-post fields.
//
/**
 * Retrieve post custom meta data field.
 *
 * @since 1.5.0
 *
 * @param string $key Meta data key name.
 * @return false|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
 */
function post_custom($key = '')
{
    $custom = get_post_custom();
    if (!isset($custom[$key])) {
        return false;
    } elseif (1 == count($custom[$key])) {
        return $custom[$key][0];
    } else {
        return $custom[$key];
    }
}

WordPress Version: 3.7

//
// Post-meta: Custom per-post fields.
//
/**
 * Retrieve post custom meta data field.
 *
 * @since 1.5.0
 *
 * @param string $key Meta data key name.
 * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
 */
function post_custom($key = '')
{
    $custom = get_post_custom();
    if (!isset($custom[$key])) {
        return false;
    } elseif (1 == count($custom[$key])) {
        return $custom[$key][0];
    } else {
        return $custom[$key];
    }
}