Get custom fields globally

Adding this to the functions.php of your wordpress theme will allow you to get custom field values globally great form themes that use a lot of custom fields.


function get_custom_field($key, $echo = FALSE) {
global $post;
$custom_field = get_post_meta($post->ID, $key, true);
if ($echo == FALSE) return $custom_field;
echo $custom_field;


get_custom_field('custom-field-name', TRUE);

Be Sociable, Share!

Leave a comment