Skip to content

Instantly share code, notes, and snippets.

@janizde
Created November 16, 2014 13:04
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 janizde/07a66746b6d66c68aec0 to your computer and use it in GitHub Desktop.
Save janizde/07a66746b6d66c68aec0 to your computer and use it in GitHub Desktop.
Examples: Retrieving Data from WP Detail Fields
<?php
/**
* WP Detail Fields: Retrvieving Data
*/
/**
* Get Post Detail function
*
* @param string $slug The Detail Fields' slug
* @param int $post_id The posts id. By default id of global $post
* @param bool $returnPost If set to true and result is of type int, returns a WP_Post with matched id. Use this for post-select fields
* @return mixed The Fields' value
*/
get_post_detail( $slug, $post_id, $returnPost );
/** Field Types: text, textarea, email, url, date, time... */
$result = get_post_detail( 'my-text-field' );
// $result: (string) "the-value"
/** Field Types: select (single), radio */
$result = get_post_detail( 'my-radio-or-select' );
// $result: (string|int) "opt-1"
/** Field Type: checkbox (multi) */
$result = get_post_detail( 'my-multi-checkbox' );
// $result: (array) array("opt-1", "opt-3")
/** Field Type: post-select */
$result = get_post_detail( 'my-post-select', false, true );
// $result: WP_Post with selected ID
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment