• I am looking for some help with custom fields. I would like to add images to a post with custom fields. I have been able to use a custom field to get 1 image into post, but how about an unlimited amount? I could just keep reusing the same custom field key (ex. ‘img’) in the same post to add multiple images.

    Also, is there to insert each image into an

    • within a div?

      I tried messing around the setting single=’false’, etc… but it returns blank with no image… I have also scoured the internet.

      Thanks a million. If I could resolve this I will be done with what I think is a nice wordpress site! Thanks again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • When you set the function call to false, ie. get_posts_meta( $post->ID , 'field' , false ), the results are returned as an array of values, instead of just a string (ie. when set to true).

    The first item is the first key in the array (which is 0), and so on..

    So let’s say you had..

    $images = get_post_meta( $post->ID , 'image' , false );

    You’d need to loop over them…. a foreach loop is proberly the easiest..

    if($images) :
    foreach( $images as $image ) { ?>
    <img src="<?php echo $image ?>" alt="" />
    <?php
    }
    endif;

    Thread Starter sam_tots

    (@sam_tots)

    Awesome, that worked! Now, if I wanted each image to get placed within 1 div and as a list.

    So the final output would look like

    <div id=”projects”>

    • <img src=”img.jpg”>
    • <img src=”img.jpg”></l1>
      etc…

    </div>

    The dynamic content is obviously between the

    • how I was able to get it to work now out puts each li in between a new div id “projects” and an ul…

      Thanks so much, I am almost there.

    Thread Starter sam_tots

    (@sam_tots)

    Never mind I got it!

    I will post what I did up here, I am sure others are looking for something similar.

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

The topic ‘Custom Field’ is closed to new replies.