Hello, I am using the clone field to clone a single field. I have a couple of questions: First of all, it seems like I cannot use the same field name for the clone field as the original field I am cloning. Is that true? Secondly, if I do use different field names, it seems like I have to call the original field name from the template to get the value and not the clone field name. Is that true?
I have looked in the posts and post_meta database tables to try to figure out how it works, so feel free to talk in “database lingo” if that helps explain.
Thank you for any insight, I confess I am quite perplexed about the clone field usage!
All field names need to be unique on the page where they are used.
A clone field works in a similar fashion to a repeater field if you use the “Prefix Field Names” setting.
Let’s say that you have a clone field named “clone_field” and you are cloning a single field with the name “text_field”.
If you set Prefix Field Names to “No” then the value of this field will be stored in the DB with the meta_key of “text_field”. If you clone this multiple times on the same page then there will be multiple fields with the same name and this will lead to conflict between them.
If you set Prefix Field names to “Yes” then this field would be saved with a meta_key of “clone_field_text_field”, removing the conflict.
Thanks very much for the quick reply! If you don’t mind, I just need a little further clarification and then I think I will understand…
Let’s use your example and say that instead of naming my fields “clone_field” and “text_field”, I named both of them “text_field”. I do not use Prefix Field. Also, I do not have multiple clone fields on the page, just the one clone field called “text_field”. Will I still get a name conflict because I have named my clone field the same name as the field I cloned (both called “text_field”)? Seems like that is what was happening to me.
And then the other clarification I’m looking for, using the same scenario above, if I do name the field being cloned “text_field” and the clone field “clone_field”, in the template do I use get_field( ‘text_field’ )? I think this is actually what worked for me, I was just confused because after going through ACF documentation I was thinking I would use get_field( ‘clone_field’ ).
Hopefully my question is clear and not confusing! Thanks in advance for taking the time to help me!
if you name both the clone field and the cloned field “text_field” and you only use this once….. to be completely honest, I do not know if this would cause a conflict. It might, but shouldn’t. I would try to stay away from doing this. It could be that when you do
get_field('text_field') that ACF may be getting confused about getting the clone or the cloned field.
If you name them differently and you do not use prefixing then you should use
get_field('text_field') but if you do use prefixing then you should use get_field(‘clone_field_text_field’)`.
Going to be completely honest, I have tried clone fields and I don’t much like them. They reduce the amount of work creating field groups, but they add to that work back in when coding the front end. It can save some time when everything is exactly the same about the fields but for me there’s not enough of an advantage with using them. And I have had problems with them when using them in flex field layouts and repeater fields.
The topic ‘Clone single field name conflict’ 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!