Created
November 16, 2014 13:04
-
-
Save janizde/07a66746b6d66c68aec0 to your computer and use it in GitHub Desktop.
Examples: Retrieving Data from WP Detail Fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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