Support

Account

Home Forums Add-ons Repeater Field True false in repeater

Helping

True false in repeater

    • zduni

    • January 9, 2019 at 1:11 am

    I Try to manage something like this, but the sub_field “zusatzbutton” doesn’t work.
    Any thought?

    <?php
    		$seite = get_field('seite');
    		$zusatzbutton = get_sub_field('zusatzbutton-check');
    
    		if($seite) {
    		  echo '<div class="seiten grid-3 wrapper">';
    		     foreach($seite as $s) {
    		         echo '
    		         <div class="seite column">
    	              <div class="seite-bild"><a href="'.$s['button-link'].'"><img src="'.$s['seite-bild'].'"></a></div>
    	              <h2>'.$s['seite-text'].'</h2>
    	              <a class="weiterlesen" href="'.$s['button-link'].'">'.$s['button-text'].'</a>';
                   
                   		if($zusatzbutton == 'yes') {
                   			echo '<a class="weiterlesen" href="'.$s['zusatzbutton-link'].'">'.$s['zusatzbutton-text'].'</a>';
                   		}
                   		
    		         echo '</div>';
    		     }
    		  echo '</div>';
    		}
    	?>
  • You can’t use get_sub_field() unless you are in a have_rows() loop. https://www.advancedcustomfields.com/resources/have_rows/

    This will return an array of rows

    
    $seite = get_field('seite');
    

    where each element of the array is a row with nested elements for each field
    example representation of this value:

    
    $seite = array(
      array(
        // row 1
        'zusatzbutton-check' => 1, / some value for this sub field
        'second-sub-field' => 'value of this field',
        // etc... 
      ),
      array(
        // row 2
        // etc...
      )
    )
    

    Have rows loop

    
    if (have_rows('seite')) {
      while (have_rows('seite')) {
        the_row();
        if (get_sub_field('zusatzbutton-check')) {
          // show information about this row
          // for more information see the link provided for have_rows()
        }
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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.