You are here:

get_post_meta( int $post_idstring $key = bool $single = false )

Retrieves a post meta field for the given post ID.

Parameters Parameters


(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

Top ↑

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.

Top ↑

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 for more info. Be careful not to mix upper and lowercase.
  • Uses: get_metadata() to retrieve the metadata.

Top ↑

Source Source

File: wp-includes/post.php

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

Top ↑

Changelog Changelog

Version Description
1.5.0 Introduced.
Was this article helpful?
Dislike 0
Views: 10