Home › Forums › Add-ons › Flexible Content Field › Flexible content need help
We got your help request! One of our agents will respond to you as soon as possible.
Xeeshan sent a message
Sep 20, 8:04pm
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
if( get_field(‘flexible_content’) ):
// loop through the rows of data
while ( has_sub_field(‘flexible_content’) ) :
if( get_row_layout() == ‘content’ ):
// no layouts found
i need reply asap please help me out
—- Versions —-
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
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;
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.