a blog about handmade code

Grabbing Custom Fields and Values

Getting the custom field can be fast. Here's an example.

<?php
global $post;
$map_location = get_post_meta($post->ID, 'Map Location', true);
?>

$post->ID is the id of the post.
Map Location is the name of the custom field. Be sure to use quotes.
true gets the first value of the custom field. Use false and it will return all the values, can be very useful if you have more than one item and loop through with a for,while, or foreach.

Add new comment

©2012 Tranzic Media / Portfolio of Vasna Sdoeung