Support » Themes and Templates » the_meta works but get_post_meta doesn’t?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Here’s the complete code… I don’t GET IT! 🙁 I’ve been looking for like 5 hours straight and I get how it should work, I just must have like 1 little thing wrong… the_meta() works fine and displays all the keys and values but if I try to get just one key and value with get_post_meta, nothing shows up. I’ve tried calling a few of the custom field keys, none come up.

    <?php get_header(); ?>
    	<div class="blog-article">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div class="post" id="post-<?php the_ID(); ?>">
    					<h1 class="post-title">
    						<?php the_title(); ?>
    					<?php get_post_meta($post->ID, 'title', true); ?>
    			<?php the_content(); ?>
    	<?php endwhile; endif; ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The reason I don’t want to use the_meta is because I need to have the keys/values in a certain order and kinda scattered… I want to be able to call each individual one with get_post_meta, for example:

    <li><?php get_post_meta($post->ID, 'title', true); ?></li>
    <li><?php get_post_meta($post->ID, 'next', true); ?></li>
    <li><?php get_post_meta($post->ID, 'other', true); ?></li>
    <li><?php get_post_meta($post->ID, 'etc', true); ?></li>
    <?php get_post_meta($post->ID, 'something', true); ?>

    Well, get_post_meta will only return the value, try adding echo before that 🙂

    I tried that before but it didn’t work either 🙁

    Even if I manually put a page id instead of $post->ID, it doesn’t work…

    Is my loop wrong? I don’t know why the_meta would work and get_post_meta wouldn’t if they are both used at the same point.

    Hi ciaravino,
    get_post_meta will be worked for custom field. Add a custom field as “title” in a particular post and put the content in the value field. See this example:

    Further need any help, i will help to you.


    Had the same problem as you, took a fair bit of googling but this site has the fix:

    Since it’s inside the loop: change $post->ID to get_the_id()
    Who knew?

    Wow that wasted a couple hours of my day before finding this post. Thanks guys. 🙂

    Hello all. i’m having problem with output of get_post_meta()

    This is my code but the get_post_meta() gives no output at all although i’m getting get_the_ID() output.

    // query_posts(‘posts_per_page=5&cat=4’);
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    echo get_the_ID();

    $slider_image = get_post_meta(get_the_ID(), ‘slider_image’, true);
    echo $slider_image;
    ” href=”<?php the_permalink(); ?>”>
    <img height=”360″ width=”825″ alt=”” class=”attachment-featured-image wp-post-image” src=”<?php echo $slider_image ?>”

    <div class=”ft-title-holder”>
    <h2><?php the_title(); ?></h2>
    <p><?php echo String::content_limit(500); ?></p>
    “> </div>
    endwhile; else:

    Can anyone help me plz!



    Forum Moderator

    what is the content of the ‘slider-image’ custom field of the post with the ID that gets shown?

    with other words, is the ID an id of a post with this customfield filled in?

    did you also try to use ‘get_post_meta($post->ID,’slider-image’,true)’ ?

    do you have a link to your site, where this slider image should be shown?

    what would ‘the_meta()’ output in the same location if you put it into the code?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘the_meta works but get_post_meta doesn’t?’ is closed to new replies.