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!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.