Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created February 27, 2012 20:39
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 wpsmith/1926880 to your computer and use it in GitHub Desktop.
Save wpsmith/1926880 to your computer and use it in GitHub Desktop.
get custom field
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