I'm very new to post meta values and implementing them into Wordpress themes. Ultimately, what I'm trying to do is list individual post meta values on specific parts of a single post. But I'm having no progress because of the fact that nothing I try seems to work. If, for example, I want to display the meta value for a key called Model
, none of these work:
<?php get_post_meta($post->ID, 'Model', true); ?>
<?php get_post_meta($post->ID, 'Model', false); ?>
<?php get_post_meta(get_the_id(), 'Model', true); ?>
Not even this works--and it should:
<?php get_post_meta( get_the_id() ); ?>
The only thing that has worked so far for listing meta values is this:
<?php the_meta(); ?>
But of course, it's no good to me because it lists all of my meta values for that post, and I need to be able to separately import individual meta values.
I know for a fact that I'm in the loop when I'm calling these functions, and I know for a fact that get_post_id()
works because I did an echo
with it. The only thing I can think is that I'm declaring the string for the $key
improperly, or declaring the boolean value for $single
improperly, and Wordpress documentation is very spotty for both of those. But then, neither $key
nor $single
was a factor in that fourth code example I listed above. So really, I'm stuck.
Can someone help me out please?
(P.S. I'm trying this meta thing with the default Twenty Eleven and Twenty Twelve themes, so the themes themselves shouldn't be the issue)
get_post_meta() returns a value, while the_meta() echoes all the metas, they're not equivalent. Have you tried this?
<?php echo get_post_meta($post->ID,'Model',true); ?>