WordPress.org

Forums

Not working (4 posts)

  1. Nith
    Member
    Posted 5 years ago #

    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.

  2. alchymyth
    Forum Moderator
    Posted 5 years ago #

    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.

  3. nouveller
    Member
    Posted 5 years ago #

    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.

  4. Nith
    Member
    Posted 5 years ago #

    Thanks!, worked like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.