get_post_meta( int $post_id, string $key = '', bool $single = false )

Retrieves a post meta field for the given post ID.



(int) (Required) Post ID.


(string) (Optional) The meta key to retrieve. By default, returns data for all keys.

Default value: ''


(bool) (Optional) Whether to return a single value. This parameter has no effect if $key is not specified.

Default value: false


(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

  • 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.


File: wp-includes/post.php

function get_post_meta( $post_id, $key = '', $single = false ) {
	return get_metadata( 'post', $post_id, $key, $single );


Version Description
1.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.