Make get_post_custom() a wrapper of get_post_meta() so that it works when cache addition is suspended and to simplify it.

Props leewillis77 for the initial patch. Fixes #19708.


git-svn-id: http://svn.automattic.com/wordpress/trunk@19906 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
duck_ 2012-02-10 22:00:37 +00:00
parent a856f757db
commit 787dd48e8b
1 changed files with 4 additions and 11 deletions

View File

@ -1513,28 +1513,21 @@ function delete_post_meta_by_key($post_meta_key) {
/** /**
* Retrieve post meta fields, based on post ID. * Retrieve post meta fields, based on post ID.
* *
* The post meta fields are retrieved from the cache, so the function is * The post meta fields are retrieved from the cache where possible,
* optimized to be called more than once. It also applies to the functions, that * so the function is optimized to be called more than once.
* use this function.
* *
* @since 1.2.0 * @since 1.2.0
* @link http://codex.wordpress.org/Function_Reference/get_post_custom * @link http://codex.wordpress.org/Function_Reference/get_post_custom
* *
* @uses $id Current Loop Post ID * @param int $post_id Post ID.
*
* @param int $post_id post ID
* @return array * @return array
*/ */
function get_post_custom( $post_id = 0 ) { function get_post_custom( $post_id = 0 ) {
$post_id = absint( $post_id ); $post_id = absint( $post_id );
if ( ! $post_id ) if ( ! $post_id )
$post_id = get_the_ID(); $post_id = get_the_ID();
if ( ! wp_cache_get( $post_id, 'post_meta' ) ) return get_post_meta( $post_id, '' );
update_postmeta_cache( $post_id );
return wp_cache_get( $post_id, 'post_meta' );
} }
/** /**