WordPress Function to Grab all custom fields globally

Grab all custom fields globally

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;
}

Then call the field with a single line

<?php get_custom_field('custom-field-name', TRUE); ?>

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *