get_post_meta( int $post_id, string $key = ”, bool $single = false )
Retrieves a post meta field for the given post ID.
Parameters Parameters
- $post_id
-
(int) (Required) Post ID.
- $key
-
(string) (Optional) The meta key to retrieve. By default, returns data for all keys.
Default value: ”
- $single
-
(bool) (Optional) Whether to return a single value. This parameter has no effect if $key is not specified.
Default value: false
Return Return
(mixed) An array if $single is false. The value of the meta field if $single is true. False for an invalid $post_id.
More Information More Information
- Please note that if a db collation is case insensitive (has with suffix _ci) then update_post_meta and delete_post_meta and get_posts() will update/delete/query the meta records with keys that are upper or lower case. However get_post_meta will apparently be case sensitive due to WordPress caching. See https://core.trac.wordpress.org/ticket/18210 for more info. Be careful not to mix upper and lowercase.
- Uses: get_metadata() to retrieve the metadata.
Source Source
File: wp-includes/post.php
2125 2126 2127 |
function get_post_meta( $post_id , $key = '' , $single = false ) { return get_metadata( 'post' , $post_id , $key , $single ); } |
View on Trac
Changelog Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |