[wp-trac] [WordPress Trac] #14017: New template "tag": get_custom_field()
WordPress Trac
noreply at wordpress.org
Tue May 27 04:27:44 UTC 2014
#14017: New template "tag": get_custom_field()
-----------------------------------+-----------------------------
Reporter: filosofo | Owner: filosofo
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Posts, Post Types | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion | Focuses: template
-----------------------------------+-----------------------------
Comment (by obenland):
There is a way to retrieve a custom field value that is somewhat agnostic
of current context: `post_custom()`
([https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/post-
template.php#L858 #]).
I suppose we could introduce a function that is a bit more coherent with
the naming conventions of template tags, and which optionally also accepts
a post id:
{{{
#!php
<?php
/**
* Retrieve the value for a post meta field.
*
* @since 4.0.0
*
* @param string $key Optional. The meta key to retrieve.
* @param int $post_id Post ID. Optional.
*
* @return mixed The value of meta data field or an empty string.
*/
function get_post_meta_value( $key, $post_id = 0 ) {
return get_post_meta( get_post( $post_id )->ID, $key, true );
}
}}}
But one could make the argument that it is not strictly necessary. If
they're looking for a meta value of a specific post, they can use
`get_post_meta()`. If they're looking for a meta value of the current
post, they can use `post_custom()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/14017#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list