Support

Account

Home Forums Add-ons Flexible Content Field Flexible content need help Reply To: Flexible content need help

  • Next time you post code please use the code button so that your code is more readable.

    I’m not sure what documentation you’re referring to, I’m going to go by this as an example http://www.advancedcustomfields.com/resources/get_row_layout/

    You’re using some incorrect function. the_sub_field() echos the content of the field. To assign that value you need to use get_sub_field(). I’ve also substitued has_sub_field() with the_flexible_field() as shown in the example.

    
      
      $quantity;
      $price;
      $color;
      $combine = array();
      $count = 1;
      if (get_field('flexible_content')):
        while (the_flexible_field("flexible_content")):
          if (get_row_layout() == 'content' ):
              
              $quantity = get_sub_field('quantity');
              $price = get_sub_field('price');
              $color = get_sub_field('color');
              $combine[] = $quantity.','.$price.','.$color;
              $count++;
          
           endif;
        endwhile;
        
        // output the array
        // you should replace this with your code to display the array
        echo '<pre>'; print_r($combine); echo '</pre>';
      
      else:
        // no layouts found
      
      endif;