get wordpress custom fields outside the loop
June 12, 2009 · Print This Article
Custom fields are very useful and are used on many WordPress blogs.
But how to easily get custom fields values outside the loop?
To display a custom field value outside the loop, simply use the following code.
Don’t forget to replace Myfield on line 4 by the name of the custom field you want to display.
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'MyField', true);
?>





















[...] LiveXP shows how to get custom fields outside the loop. If creating a theme options page is beyond your skill, you can create a private page and store / retrieve the meta values from custom fields attached to that page wherever you need to. [...]