I’m trying to echo the key of a custom field (value, such as a URL set while editing a post) back into the document. Here’s the overall code:
<div id="feature" class="clearfix">
<?php
$feature_post = get_posts('category=3&numberposts=1');
foreach( $feature_post as $post ) :
?>
<div class="feature_post" style='<?php echo get_post_meta($post->ID, 'feature', true); ?>'>
<h2><?php the_title(); ?></h2>
</div>
<?php
endforeach;
?>
</div>
Specifically, this is the line of code:
<?php echo get_post_meta($post->ID, 'feature', true); ?>
That doesn’t print anything – any ideas?
The custom field on the post is already ‘feature’, there’s no CSS issues or Javascript, it’s just not returning the values.
Please add
global $post;before you callget_posts()function and don’t use $post naming in foreach() loop, then see if it works or not! If failed simply use this code instead: