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

  • One more question, and I’m happy to pay you for time, just shoot me your PayPal:

    So the above works beautifully. Now what if I wanted to also pull a field or fields from the existing repeater field, meaning not the post object. I’m trying this, but it’s not working:

    	//Loops through the repeater
    while (have_rows('favorite_cars')) {
    	//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');
    		//Fetch the image field from the carsandtrucks post
    		$image = get_field('main_image', $car_object->ID);
    	//Echo out the image with the medium size. Change this as you like!
    	echo '<img src="' . $image . '" width="' . $image . '" height="' . $image . '" alt="' . $image['alt'] . '" />';
            echo '<div>$title</div>';
            echo '<div>$summary</div>';

    So as you can see, I’m trying to pull a title and summary (both ACF fields) from the current post, along with the post object from the other.

    In case this doesn’t make sense, someone is choosing a car from another CPT, and then entering their own title and descriptions on the current post.

    Thank you!