Support

Account

Home Forums Add-ons Flexible Content Field Subfield to array

Solved

Subfield to array

  • Hello,

    I have a flexible content field with subfields. I’m using this code to display subfields:

    
    if (have_rows('fcf_name')) {
      while(have_rows('fcf_name')) {
      the_row();
        echo get_sub_field('subfield_name');  //this echoes value for each flexible content item
      }
    }
    

    Now let’s say I have multiple flexible content items. How can I add subfield values from multiple flexible content’s to an array. So If I have 3 flexible contents, an array with 3 values from subfields must be created.

    Regards

  • Ah, so simple…

    if (have_rows('fcf_name')) {
      while(have_rows('fcf_name')) {
      the_row();
        $array[] = get_sub_field('subfield_name');
      }
      print_r($array);
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.