Grow your CSS skills. Land your dream job.

Help please custom fields

  • # July 29, 2009 at 2:04 pm

    Hey,

    Im really stumped on some custom field generation.

    I am trying to call a custom field ‘featured’ which has a url link to an image path.

    Code:
      < ?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      < ?php
      $featured = get_post_meta($post->ID, ‘featured’, $single);
      ?>

      < ?php
      echo "

    • “;
      ?>
      < ?php endwhile; endif; ?>

    In the particular page this code is referencing i have more than one image, but uses the same key id ‘featured’.

    My issue is that the echo is not looping through and only pulling out the first image.

    Can anyone lend a hand so that i can pull all my images out one after the other.

    Thanks
    B

    # July 29, 2009 at 4:04 pm

    Did you look through the WordPress support forms? It looks like you need a foreach statement. This seems similar to your problem:

    http://wordpress.org/support/topic/282336

    Code:
    < ?php
    $cf1values = get_post_meta($post->ID, ‘cf1′, false);
    echo “
    "; print_r($cf1values); echo "

    “;
    if ($cf1values) {
    foreach ($cf1values as $cf1value) {
    echo ‘

    for post id: ‘.$post->ID.’ cf1 value is: ‘.$cf1value .’

    ‘;
    }
    }
    ?>

    # July 29, 2009 at 5:19 pm

    Magic ‘downstairsdev’

    using the foreach statement i was able to echo out all the custom fields with the name ‘featured’.

    Here is the code that got it working:

    Code:
    < ?php
    $featured = get_post_meta($post->ID, ‘featured’, false);
    //echo “
    "; print_r($featured); echo "

    “;
    if ($featured) {
    foreach ($featured as $image) {
    echo ““;
    }
    }
    ?>

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".