post_custom() WordPress Function
The post_custom() function is a versatile way to get custom fields for a post in WordPress. It can be used to get data for a specific post, or to get an array of all custom fields for a post. You can also specify which custom field you want to get, or you can get all custom fields for a post as an associative array.
post_custom( string $key = '' ) #
Retrieves post custom meta data field.
Parameters
- $key
(string)(Optional)Meta data key name.
Default value: ''
Return
(array|string|false) Array of values, or single value if only one element exists. False if the key does not exist.
Source
File: wp-includes/post-template.php
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 ]; } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |