Home › Forums › General Issues › Problems with the new clone field
Hi,
I’ve taken the new clone feild on as I’ve been using 3rd party plugins that have been too slow and after doing some tests in the backend I really liked the speed of it, but from the frontend I’m having problems.
Could someone help explain how a nested Clone field would look with a flexible content field?
I’m finding it hard to work this out.
This is the ACF setup I have ( it’s exactly what they say here, but give no code examples for it https://www.advancedcustomfields.com/resources/clone/ ‘Cloning a clone’ )
Page field group – with Clone Field calling … > Flexi Fields – field group that is mainly fexible content with Clone Fields calling … > Elements, these have a repeater with sub fields within it.
I can tunnel down and get to the point where I can tell what layout I’m using in the flexible field, but not past that.
I know the data is there as I can see it using acf viewer …
Array
(
[flexi_layouts] => Array
(
[] =>
[layout_elements] => Array
(
[0] => Array
(
[acf_fc_layout] => layout_component_element_column // I can get to here, but not call anything beyond this.
[component_element_column] => Array
(
[] =>
[element_column] => Array
(
[0] => Array
(
[column_content] =>
[column_width] => 12
[column] =>
test column 1
[column_start_with_drop_cap] => false
[column_add_margin_to_the_top] => 0
[animate_elements] =>
[column_section_animation] => Array
(
[0] => none
)
[additional_element_options] => Array
(
[0] => Array
(
[element_id] =>
[element_visible_on] =>
)
)
)
[1] => Array
(
[column_content] =>
[column_width] => 12
[column] =>
test column 2
[column_start_with_drop_cap] => false
[column_add_margin_to_the_top] => 0
[animate_elements] =>
[column_section_animation] => Array
(
[0] => none
)
[additional_element_options] => Array
(
[0] => Array
(
[element_id] =>
[element_visible_on] =>
)
)
)
)
[full_screen_options] =>
[full_screen_option] => Array
(
[0] => Array
(
[component_option_full_screen_section] => off
[component_option_section_background] =>
[component_option_section_text_colour] =>
)
)
)
)
)
[select_content_editor] => flexi
[show_page_title] => true
[display_background_image] =>
[background_colour] => #ffffff
[background_image] =>
[image_repeat] => Array
(
[repeat-y] => repeat-y
)
[image_position] => Array
(
[] =>
)
[position_top] =>
[position_left] =>
[image_size] => Array
(
[auto] => auto
)
[image_width] =>
[image_height] =>
[image_attachment] => Array
(
[scroll] => scroll
)
[custom_code] => Array
(
[0] => Array
(
[custom_code] =>
)
)
)
)
I’ve tried this …
if( get_row_layout() == 'layout_component_element_column' ) {
echo '<h1>layout_component_element_column!</h1>';
// flexi_layouts > layout_elements > component_element_column > element_column
while( have_rows( 'flexi_layouts_layout_elements_component_element_column_element_column' ) ) : the_row();
echo '<h1>flexi_layouts_layout_elements_component_element_column_element_column!</h1>';
endwhile;
while( have_rows( 'flexi_layouts_layout_elements_component_element_column' ) ) : the_row();
echo '<h1>flexi_layouts_layout_elements_component_element_column!</h1>';
endwhile;
while( have_rows( 'layout_elements_component_element_column' ) ) : the_row();
echo '<h1>layout_elements_component_element_column!</h1>';
endwhile;
while( have_rows( 'component_element_column' ) ) : the_row();
echo '<h1>component_element_column!</h1>';
endwhile;
while( have_rows( 'element_column' ) ) : the_row();
echo '<h1>element_column!</h1>';
endwhile;
}
but nothing is working.
I’ve looked at the documentation, but it only speaks about having a senario like this and not giving any code examples.
Please, can anyone help with this? I really need to get this to work.
I just need a code example of a flexible field with a clone field that is a repeater field.
I’ve tried something like this but nothing works.
if ( have_rows('cloneField_flexibleContentField_cloneField_repeaterField') ){
echo '<h1>We have more rows!</h1>';
}
I can only seem to do a have_rows once. I know the data is there, I just need to be able to call it out.
Array ( [] => [layout_elements] => Array ( [0] => Array ( [acf_fc_layout] => layout_component_element_column [component_element_column] => Array ( [] => [element_column] => Array ( [0] => Array ( [column_content] => [column_width] => 12 [column] =>
test column 1
[column_start_with_drop_cap] => false [column_add_margin_to_the_top] => 0 [animate_elements] => [column_section_animation] => Array ( [0] => none ) [additional_element_options] => Array ( [0] => Array ( [element_id] => [element_visible_on] => ) ) ) [1] => Array ( [column_content] => [column_width] => 12 [column] =>
test column 2
[column_start_with_drop_cap] => false [column_add_margin_to_the_top] => 0 [animate_elements] => [column_section_animation] => Array ( [0] => none ) [additional_element_options] => Array ( [0] => Array ( [element_id] => [element_visible_on] => ) ) ) ) [full_screen_options] => [full_screen_option] => Array ( [0] => Array ( [component_option_full_screen_section] => off [component_option_section_background] => [component_option_section_text_colour] => ) ) ) [text] => some text ) ) [select_content_editor] => flexi [show_page_title] => true [display_background_image] => [background_colour] => #ffffff [background_image] => [image_repeat] => Array ( [repeat-y] => repeat-y ) [image_position] => Array ( [] => ) [position_top] => [position_left] => [image_size] => Array ( [auto] => auto ) [image_width] => [image_height] => [image_attachment] => Array ( [scroll] => scroll ) [custom_code] => Array ( [0] => Array ( [custom_code] => ) ) )
Hi @cloud9
Thanks for the q’s.
Are you able to export your field groups to .json and attach them to your reply?
This way, i can import them on my local site and test it out.
For now, I suggest testing what data is loaded by the flexible content field uysing the get_field function() like so:
<?php
echo '<pre>';
print_r( get_field('flexi_layouts') );
echo '</pre>';
die;
?>
* assuming that ‘flexi_layouts’ is your parent field.
Hi, I have a similar problem.
Display: seamless = I got duplicate content and have_rows don’t work.
Display: group = only have_rows don’t work but the backend is fine.
I attached my fields. I think it is the same problem like above. It only happend if flexible content was cloned.
ACF Version 5.4.2
Wordpress 4.5.3
I raised a support ticket also for this issue ( for the plugin I have paid for ), only to be told look for a freelancer who can help.
Very helpful thanks guys.
This Notice I also received. The suppot did not understand the failure.
So what can we do? 😉 I search myself the error.
I find no solution. It’s definitely a bug in the core. We need help from @elliot …
I think I have the same problem here. @elliot do you understand the problem and can you give some tipps?
The problem that I see is, that there is no function to point to the nested field. For my case the ‘modules’ array.
Example output of $rows = get_field( 'rows' );
:
Array
(
[0] => Array
(
[acf_fc_layout] => 2_columns
[column_1] => Array
(
[modules] => Array
(
[0] => Array
(
[acf_fc_layout] => button
[text] => 1st button text
[url] =>
)
)
)
[column_2] => Array
(
[modules] => Array
(
[0] => Array
(
[acf_fc_layout] => button
[text] => 2nd button text
[url] =>
)
)
)
)
)
I can loop over the layouts of the rows flexible content field, but I can’t loop over the clone fields of these layouts (modules). Attached you can find my exported field groups.
Hi guys
I’ve just been testing this issue on a support ticket and have some useful info for you. I’ve found a scenario where the have_rows function will fail, and it’s all to do with the clone field’s display setting.
The issue can be found when a clone field is used as a sub field to clone in another loop-able field (repeater / flexible content). If this clone field uses the ‘display = block’ setting, the have_rows function will fail.
This issue is only specific to a sub clone field. If the clone field was a parent field, there is no issue. Similarly, if the clone field’s display setting is set to ‘seamless’, there will also be no issue.
The issue is due to the way the clone field loads it’s value when ‘display = block’. If you use the get_field() function and simply print out the value, you will notice a slightly different data structure for the block/seamless settings.
To solve the problem, please use the ‘seamless’ setting for your nested clone field. I will look into finding a solution for this issue.
Thanks
Elliot
Hey Elliot,
thanks for getting back to us. I just tested it and can’t confirm that this will work for me. I get a different structure for the output but the “modules” are empty now and the 2nd column is overriding the content of the 1st column. Attached again the current setup of the field groups.
Array
(
[0] => Array
(
[acf_fc_layout] => 2_columns
[modules] =>
)
)
Hi @drumba
Thanks for the reply. I’ve imported your group and can see your issue is different from what I explained above.
In your case, you are seamlessly cloning in the same field twice into the same row. ACF uses the field’s key in the $_POST name data structure, so these 2 fields are overriding each other.
I can see what you are trying to do with the modules, and it’s quite smart, but I’m not sure the clone field will allow it…
Perhaps I can use the clone field’s key within the field name. This is how the ‘block’ display setting works. Perhaps I need to also do this for the seamless setting…
Hey @elliot,
when I use the “block” display settings everything in the backend is fine but I can’t access the content from the frontend.
Does it mean that my way with the rows and modules will not work? If so I have to find another way.
Hi All,
I had to abandon this due to deadlines on a project, but I really want it to work and I will be trying again on my next project. So I’m keen to see a fix too.
Hi @drumba
I’m sorry to say but currently, your setup wont work.
That said, I’ll start work tomorrow debugging this and will find a solution!
I’ve got a few threads regarding clone field bugs and it sounds like there are 2 problems:
1. The seamless setting is not allowing a sub clone field to save data correctly when multiple clone fields are cloning in the same field. An edge case yes, but in @drumba case above, it’s quite a useful setup
2. When using the ‘display = block’ setting, the have_rows function will not work correctly for a sub clone field.
I’ll be in touch. For now, please look for an alternative solution, or consider working on another project for a few weeks?
🙂
Thanks
E
Thanks a lot @elliot I am looking forward to it. If you need some help for testing, let me know.
I am sad to say that delaying the current project is no option. The deadline is in 3 weeks. 🙁
@markus I’m not sure if this will help, but i’s what I’m using as an alternative right now.
https://codecanyon.net/item/advanced-custom-fields-component-field-addon/13770937
@cloud9 thanks for the recommendation. Normally I don’t trust all the envato stuff. Have you tested it and used it on production already?
Hi guys
I’m currently working on this issue and believe I can fix both bugs in my comment above. Can you please email me directly with your github username? I would like to invite you into the ACF PRO repo so you can pull beta code and help test this patch!
Please email [email protected]
Thanks
Elliot
Hi guys
Update
I believe I have fixed issue #1 where ‘seamless’ sub clones were not able to save correctly.
I’ve done some initial testing of issue #2 but this looks much more complicated than I thought. For now, please load the value of your sub clone field ( using get_sub_field(‘sub_clone_name’) ) and loop over it’s values using a foreach loop. The data should be formatted correctly so your HTML results should work as expected.
I’ll be working on this and will report back with any news
@markus yeah, I’ve been using it for a while. It good, but when you start having a lot of layouts in Flexi it does slow down a little. but as long as you plan for this it works well. I wanted to use @elliot’s version though as I think it will be better in the long run.
But as I say it works right now for me, and I will switch in the future.
Hi @elliot Any update on this. I would really like to switch to your method
The topic ‘Problems with the new clone field’ is closed to new replies.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.