WordPress – Get Custom Field Inside and Outside The Loop

Posted by on Mar 18, 2010 in Wordpress | 0 comments

Getting custom fields in WordPress.

In the Loop: (Results for Posts within the Loop)

get_post_meta($post->ID, 'key name', true); //single result returned in a string

get_post_meta($post->ID, 'key name', flase); //all results returned in an array

Outside the Loop: (Result for Identified Post anywhere outside the loop ie. sidebar, header, footer)

global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'customField', true);
468 ad

Leave a Reply