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

Retrieve post meta field for a post.


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.

Default value: false


Return

(mixed) Will be an array if $single is false. Will be value of meta data field if $single is true.


Source

File: wp-includes/post.php

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


Changelog

Changelog
Version Description
WP-1.5.0 Introduced.