• Hey guys, I need some help…

    I’ve got this on a page:

    <?php query_posts('cat=8');
    while (have_posts()) : the_post(); ?>
    
    	<article class="item">
    		<a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_directory'); ?>/images/vi_itemThumb.png" alt="<?php the_title() ?>" />
    		<h2><?php the_title() ?></h2></a>
    		<p><?php get_post_meta(the_ID(), 'blurb', TRUE); ?></p>
    	</article>
    
    <?php endwhile;
    wp_reset_query();
    ?>

    but the get_post_meta is just displaying the post’s id, I want it to display the contents of the custom field.

    What am I doing wrong here?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try using “$post_id” instead of “the_ID()” if memory serves that includes the echo command to output it to the screen.

    Thread Starter bphil00

    (@bphil00)

    <p><?php get_post_meta('echo $post_id', 'blurb', TRUE); ?></p>

    this now displays nothing, not even the id

    you want this:

    <?php get_post_meta($post_id, ‘blurb’, TRUE); ?>

    Thread Starter bphil00

    (@bphil00)

    still displays nothing ??

    Try this:
    <?php get_post_meta(get_the_ID(), 'blurb', TRUE); ?>

    Most WordPress loop functions like “the_content()” and “the_title()” directly output the information, instead of returning it for use in other functions. Most of them also have a “get_the_content()” and “get_the_title()” alternative for use in these situations instead.

    So for example, you can do <?php the_title(); ?> to output the post’s title, or <?php echo get_the_title(); ?> (With “the_xxxx()”, you don’t need to echo, they do that bit themselves).

    I hope that makes sense ??

    Thread Starter bphil00

    (@bphil00)

    boom!
    and there it is, thank you japh!
    with just one minor adjustment to your suggestion,
    adding echo before get_post_meta:

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

    Oh great, my pleasure! I missed that, so I’m glad I included the extra explanation ??

    Thread Starter bphil00

    (@bphil00)

    yes, your explanation is what made me think to try that. thanks again!
    also thanks tomaltman for your help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘get_post_meta returning post id instead of the value’ is closed to new replies.