Home › Forums › ACF PRO › Is it safe to use the same field name in different field groups › Reply To: Is it safe to use the same field name in different field groups
@acf-support forgive me for resuming an old post, but it would seem the fields get confused script-wise if they have the same name.
I encountered the need to copy all ACF fields from a group_a
of a post type type_a
to a group_b
of a post type type_b
due to an analysis mistake.
So, let’s consider this code snippet
if ($tecnologie = get_field('tecnologie', $post->ID)) {
$tecnologie_new = '<ul>';
foreach ($tecnologie as $tecnologia) {
$tecnologie_new .= '<li>';
$tecnologie_new .= $tecnologia['tecnologia'];
$tecnologie_new .= '</li>';
}
$tecnologie_new .= '</ul>';
update_field('tecnologie', $tecnologie_new, $new_id);
}
Here, $post
is of type type_a
and $new_id is the ID of a new post I created of type type_b
. In both field groups there’s a field called tecnologie
, which is a Repeater in the first type and a WYSIWYG Editor in the second. I basically need to turn the repeated rows into a <ul>
tag.
Post type_a
field group, field tecnologie
:
Post type_b
field group, field tecnologie
:
The above script returns an error:
( ! ) Warning: Invalid argument supplied for foreach() in (…)\wp-content\plugins\advanced-custom-fields-pro\pro\fields\class-acf-field-repeater.php on line 844
Because the type of field the plugin considers is the Repeater, despite the required update is on the WYSIWYG.
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.