Home Forums Add-ons Repeater Field if/else within a sorted 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">
    		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];
    				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>';
        			echo 'something else';
  • Hi @marenne

    You can use an if / else like so:

    if( $row['afbeelding'] )
        // image does exist
        // 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. It seems like I put my if statement in the wrong place!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘if/else within a sorted repeater field’ is closed to new replies.