Skip to content

Instantly share code, notes, and snippets.

@dougalcampbell
Created August 21, 2012 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dougalcampbell/3417835 to your computer and use it in GitHub Desktop.
Save dougalcampbell/3417835 to your computer and use it in GitHub Desktop.
WordPress snippet: get single post custom value
/**
* 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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment