• Hello,

    I’m using the following code to pull the value of a custom field:

    <?php
    	$featuredPosts = new WP_Query();
    	$featuredPosts->query('showposts=10&cat=4');
    	while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
    ?>
    
    <li><img src="<?php $image = get_post_meta(get_the_ID(), 'folio-image', TRUE); ?>"  alt="" /></li>
    
    <?php endwhile; ?>

    But the code returns nothing, the output is as follows:

    <li><img src="" alt=""></li>

    Anyone know what the problem is:

    Note: There is a custom field called ‘folio-image’ and it has a value.

Viewing 3 replies - 1 through 3 (of 3 total)
  • if you want to output the image url, you need to use ‘echo’:

    <li><img src="<?php echo get_post_meta(get_the_ID(), 'folio-image', TRUE); ?>" alt="" /></li>

    in your code, you simply ‘loaded’ the custom field value into a variable called $image.

    Try:

    <li><img src="<?php echo get_post_meta(get_the_ID(), 'folio-image', TRUE); ?>" alt="" /></li>

    get_post_meta only returns a value, it doesn’t echo it. If you still have no luck try changing get_the_ID() for $post->ID.

    Thread Starter Nith

    (@nith)

    Thanks!, worked like a charm.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not working’ is closed to new replies.