get_post_custom() WordPress Function

The get_post_custom() function is used to retrieve custom fields for a post. This function can be used within the loop or outside of the loop.

get_post_custom( int $post_id ) #

Retrieve post meta fields, based on post ID.


Description

The post meta fields are retrieved from the cache where possible, so the function is optimized to be called more than once.


Top ↑

Parameters

$post_id

(int)(Optional) Post ID. Default is the ID of the global $post.


Top ↑

Return

(mixed) An array of values. False for an invalid $post_id (non-numeric, zero, or negative value). An empty string if a valid but non-existing post ID is passed.


Top ↑

More Information

See also get_post_custom_keys() and get_post_custom_values()


Top ↑

Source

File: wp-includes/post.php

function get_post_custom( $post_id = 0 ) {
	$post_id = absint( $post_id );
	if ( ! $post_id ) {
		$post_id = get_the_ID();
	}

	return get_post_meta( $post_id );
}


Top ↑

Changelog

Changelog
VersionDescription
1.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More