Home › Forums › Add-ons › Repeater Field › if/else within a sorted repeater field
I am trying to display a different output when a repeater field doesn’t have an image (afbeelding) uploaded to it. My code below just outputs everything twice. Please, can you tell me what I am doing wrong?
<?php $repeater = get_field('advertenties');
foreach( $repeater as $key => $row )
{
$column_id[ $key ] = $row['datum'];
}
array_multisort( $column_id, SORT_DESC, $repeater );
?>
<div id="advertenties">
<?php
foreach( $repeater as $row )
{
$attachment_id = $row['afbeelding'];
$image = wp_get_attachment_image_src( $attachment_id, "thumbnail" );
// url = $image[0];
// width = $image[1];
// height = $image[2];
if($row['afbeelding'])
{
echo '<div id="contentwrapper" style="clear:both;">
<div class="nine columns" role="main">';
echo '<b>' . $row['datum'] . ' - ' . ucfirst($row['type']) . '</b><Br>
<p>' . ucfirst($row['tekst']) .'</p></div>';
echo '<aside class="three columns" id="afbeeldingssidebar">
<img src="' . $image[0] . '" width="' . $image[1] .'" height="'. $image[2]. '" /></aside>
<br class="clear" /></div>';
}
else;
{
echo 'something else';
}
}?>
</div>

Hi @marenne
You can use an if / else like so:
if( $row['afbeelding'] )
{
// image does exist
}
else
{
// image does no exist
}
Yes, that is what I did, but it seems like its never empty (and returns both if and else). Maybe because of the multisort? I just can’t figure it out…

Hi @marenne
an if / else can’t run both. You must be seeing another issue. Perhaps you need to do some debugging? Print out variables and see visually what is happening in your code line by line.
Thanks
E
The topic ‘if/else within a sorted repeater field’ is closed to new replies.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.