WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Custom Fields Creator] grab first image from repeatable image field (1 post)

  1. coloradocolin
    Member
    Posted 1 year ago #

    So I have used this code successfully to display images uploaded to a post in a single field (with two entries). However I have now made this field repeatable. How can I modify this code so I only show the images from the first field? Right now it outputs all of the images attached to that post. I really don't know php that well at all, and have been searching for hours, but just can't figure it out.

    $productimgs = get_post_meta( $post->ID, 'productimg', true );
    if (is_array($productimgs) & $productimgs != '' ) {
    	foreach($productimgs as $productimg) {
    		$image_color = wp_get_attachment_image_src( $productimg['product-image-color'], 'grid-large' );
    		$image_bw = wp_get_attachment_image_src( $productimgbw['product-image-bw'], 'grid-large' );
    			echo '<li>';
    			echo '<img class="desat" src="' . $image_bw[0] . '"  />';
    			echo '<img class="sat" src="' . $image_color[0] . '"  />';
    			echo '</li>';
    	    }
    	 }

Topic Closed

This topic has been closed to new replies.

About this Topic