public
Created

WordPress snippet: get single post custom value

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10
/**
* Get a single text value for a post custom field in WordPress, bypassing the normal array return.
*
* From a discussion on Twitter, which prompted me to post this. Many people seem to be
* unaware of PHP's `list()` operator (it's not, technically, a function).
*
* If you are not in the loop, you can pass a post ID as a second parameter.
*/
 
list( $val ) = get_post_custom_values( 'key' );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.