Function: get_post_meta

get_post_meta( integer $post_id, string $key, boolean $single )

Retrieves a post meta field for the given post ID.

Shortcut: gpm

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.


Name Type(s) Default Value Description
$post_id integer

Post ID.

$key string ''

Optional. The meta key to retrieve. By default, returns data for all keys. Default empty.

$single boolean false

Optional. If true, returns only the first value for the specified meta key. This parameter has no effect if $key is not specified. Default false.



Will be an array if $single is false. Will be value of the meta field if $single is true.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.