{"id":19005367,"date":"2026-08-28T09:20:34","date_gmt":"2026-08-28T09:20:34","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/fix-acf-bidirectional-relations\/"},"modified":"2026-08-28T09:20:34","modified_gmt":"2026-08-28T09:20:34","slug":"fix-acf-bidirectional-relations","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/fix-acf-bidirectional-relations\/","title":{"rendered":"Fix ACF Bidirectional relations"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While working on a project, I found that if you clone a post that had a bidirectional connection to another post, the connection was correctly cloned the other post, but the connection back wasn&#8217;t made. This makes sense since you&#8217;re not touching that other post. ACF has had this bidirectional option for a while and cloning posts that use this, effectively breaks the connection from one side. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I wrote a function that hooks into your &#8216;duplicate_post_post_copy&#8217; and resaved any bidirectional ACF field, which correctly creates the connection in both directions, fixing this issue. Is this something you&#8217;d consider adding to the plugin? Or would you tell me: create your own add-on plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_action('duplicate_post_post_copy', 'resync_bidirectional_fields_after_duplicate', 20, 2);<br \/><br \/>function resync_bidirectional_fields_after_duplicate($new_post_id, $post)<br \/><br \/>{<br \/><br \/>if (!function_exists('get_field_objects')) {<br \/><br \/>return;<br \/><br \/>}<br \/><br \/>$fields = get_field_objects($new_post_id, false);<br \/><br \/>if (empty($fields)) {<br \/><br \/>return;<br \/><br \/>}<br \/><br \/>foreach ($fields as $field) {<br \/><br \/>if (empty($field&#091;'bidirectional']) || empty($field&#091;'bidirectional_target']) || empty($field&#091;'value'])) {<br \/><br \/>continue;<br \/><br \/>}<br \/><br \/>delete_field($field&#091;'key'], $new_post_id);<br \/><br \/>update_field($field&#091;'key'], $field&#091;'value'], $new_post_id);<br \/><br \/>}<br \/><br \/>}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-19005367","topic","type-topic","status-publish","hentry","topic-tag-post-object","topic-tag-acf","topic-tag-bidirectional","topic-tag-relationship"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19005367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19005367\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19005367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}