Using Custom Fields outside The Loop in Wordpress

Discussion in 'PHP' started by TheCarlisle, Feb 20, 2011.

  1. #1
    I found this little nifty piece of code to be extremely helpful, I hope you do too:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'Custom_Field_Name', true);
    wp_reset_query();
    ?>

    Be sure to keep those half-bracket things around your own custom field name.
     
    TheCarlisle, Feb 20, 2011 IP