Support

Account

Home Forums Add-ons Flexible Content Field Flexible content need help

Helping

Flexible content need help

  • Hello Xeeshan,

    We got your help request! One of our agents will respond to you as soon as possible.

    Thanks!

    Xeeshan sent a message
    Sep 20, 8:04pm
    hi

    im using ACF plugin and in that im using flexible content , i have added a main field with the name flexible_content and in that i have created a layout with name content and its type is table, in that i have 3 fields quantity, price and color. i have added into custom post type in wordpress and what i want to do is i want to get all the values and store them into an array like

    for first section values goes into array like this [“quantity, price, color”]

    im unable to do that with your given supportive code , eithe im unable to understand this flow or that supportive code is not for this purpose

    please help me out on this

    this is my code

    $quantity;
    $price;
    $color;
    $combine=array;
    $count=1;
    if( get_field(‘flexible_content’) ):

    // loop through the rows of data
    while ( has_sub_field(‘flexible_content’) ) :

    if( get_row_layout() == ‘content’ ):

    $quantity=the_sub_field(‘quantity’);
    $price=the_sub_field(‘price’);
    $color=the_sub_field(‘color’);

    endif;
    $combine[]= $quantity.’,’.$price.’,’$color;
    $count++;
    endwhile;

    else :

    // no layouts found

    endif;

    i need reply asap please help me out

    —- Versions —-
    ACF v5.2.6
    WP v4.3.1

  • 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;
      
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Flexible content need help’ is closed to new replies.