Support

Account

Home Forums Front-end Issues Extracting Post Object data from within a Repeater Reply To: Extracting Post Object data from within a Repeater

  • Hi!

    You’ve probably set the return value for the image field to be URL rather than image object. So you should not use that markup for the image. Here’s a complete version of what you’re doing:

    
    <?php 
    //check for the repeater first. We dont want to do a while loop if there are none!
    if(have_rows('favorite_cars')){
    	
    	//Loops through the repeater
    	while (have_rows('favorite_cars')) {
    		the_row();
    		
    		//fetches the post object field. Assumes this is a single value, if they can select more than one you have to do a foreach loop here like the one in the example above
    		$car_object = get_sub_field('select_car');
    	    $title = get_sub_field('car_title');
    	    $summary = get_sub_field('car_summary');
    		if($car_object){
    			//Fetch the image field from the carsandtrucks post
    			$image = get_field('main_image', $car_object->ID);
    		}
    		
    		//Echo out the image. Since you set it to only return the image URL you can only use this for src. Change the field settings to object if you want to use the version i previously posted. 
    		echo '<img src="' . $image . '" />';
    	    echo '<h2 class="favorite-car-title"><' . $title . '</div>';
    	    //Depending on what kind of field the summary is you want the <p> tag around it.. If the field is a wysiwyg field or a textarea with automatic p-tags, remove the <p> and </p> from the code. 
    	    echo '<div class="favorite-car-summary"><p>' . $summary . '</p></div>';
    		
    	}	
    	
    } 
    ?>
    
    

    Its such a small thing so don’t worry about compensation!