custom fields wordpress

I am trying to add a value assigned in the custom field by doing a post in these following steps: I make a new post, add a new custom field where i specify a name and a value.


I add the following scripts to index.php loop exactly below where the while and its parameter begins and to the HTML where I want the field added respectively

<?php while ( have_posts() ) : the_post(); ?>
<?php the_meta();?>

<?php echo get_post_meta(get_the_ID(), 'key');?>

The hard part for me to understand if i am doing right is the HTML. when i launch the site using firefox and firebug, I detect the post and find the html where the field is supposed to be added. But I noticed that WP automatically generates paragraph tags for the original post, so i honestly dont know where i am supposed to add the get_post_meta for it to be added into my post.

Solutions Collecting From Web of "custom fields wordpress"

The update_user_meta and get_user_meta functions are what you want, without having to fool around with any database connections or SQL. All it takes is one include statement in your theme, and a bit of PHP magic to call the meta functions.

Check out my code, which accomplished what you are trying to do, on Github ( It should serve as a good example. I also have a description with embedded code on my blog: Using WordPress As A Pay-For-Access System.

Alternatively, you can check out how I added code to my footer to show text based on custom fields (in this case, hours remaining in a free trial). Looking at what you tried to do, you might add similar code to your theme’s header.php instead.

$current_user = wp_get_current_user();
$subscription = get_user_meta($current_user->ID, 'subscription', true);
if($subscription != "true")
$time = (80000 - (intval(time()) - intval($_COOKIE['seshCurrent'])))/3600;
if(intval($time) < 0)
    $time = 22.3;
echo("$time hours remaining in this session");