WordPress: Get custom field function
On several WordPress projects I've needed to get the value of a custom field. Not too difficult using the get_post_meta command, but I wanted a little quicker way. So I now add this little function to the functions.php file on themes I'm working on.
PHP:
-
function getMeta($key)
-
{
-
global $post;
-
return get_post_meta($post->ID, $key);
-
}
Say you've got a custom field name thisIsMyCustomField, you'd just do this to display the value.
PHP:
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.