Created
February 27, 2012 20:39
-
-
Save wpsmith/1926880 to your computer and use it in GitHub Desktop.
get custom field
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
function genesis_get_custom_field($field, $single = true) { | |
global $id, $post; | |
if ( null === $id && null === $post ) { | |
return false; | |
} | |
$post_id = null === $id ? $post->ID : $id; | |
$custom_field = get_post_meta( $post_id, $field, $single ); | |
if ( ( $custom_field ) && ( !is_array($custom_field) ) ) { | |
/** sanitize and return the value of the custom field */ | |
return stripslashes( wp_kses_decode_entities( $custom_field ) ); | |
} | |
elseif ( ( $custom_field ) && ( is_array($custom_field) ) ) { | |
foreach ( $custom_field as $key => $value ) { | |
$custom_field[$key] = stripslashes( wp_kses_decode_entities( $value ) ); | |
} | |
return $custom_field; | |
} | |
else { | |
/** return false if custom field is empty */ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment