Bidirectional fields not updating as expected
-
Hi there,
I’m trying to get bidirectional fields to update properly.
We have CPT [professors] and [courses]. I’ve added a [relationship] field for both, each pointing to one another from both sides.Now when adding Prof to a Course, the Prof seems to be updated correctly. However, when I save a Prof with course X, the course X only shows that professor after a refresh, instead of any/all previously selected Profs.
So then it’s possible for a professor to be assigned to Course X, but not actually showing up inside the course.
I’ve already tried renaming the bidirectional fields, running code below (saving all pages empty, then adding any relations), but nothing seems to solve this.
// always update values of all bidirectional fields add_filter('acfe/bidirectional/force_update', '__return_true'); // or target a specific field only add_filter('acfe/bidirectional/force_update/name=my_field', '__return_true');
Any idea what’s going on here?
Best,
Dave
-
Hello,
Thanks for the feedback!
I just ran some tests using the specifications you described, and it works fine on my end. Here is the video demo of my test.
If you use a Post Object Field instead of a Relationship Field, please make sure that you allowed “multiple selection”. In order to receive multiple values, the Post Object has to have this setting enabled.
You could try to setup a clean WP install with ACF + ACF Extended and try that simple setup on it. Here are the Field Groups json files that you can use to import the same setup as in my demo:
Note that in my case the post types are named
course
andprofessor
so you might would like to tweak these settings in the Field Groups (including in the Relationship fields “allowed post types”) to reflect your post type names.If you managed to make it work on a clean install, but not on your custom website then you might have some custom code or third party plugin compatibility issue.
In order to isolate the issue, I would recommend clone your website on a development / staging environment using Duplicator or your hosting backup solution. Then try to disable all your plugins one-by-one (at the exception of ACF Pro & ACF Extended) until you find which one cause the issue.
If the problem persists, I would suggest switch to the native WP Twenty Twenty Two theme, to make sure you don’t have any custom code in your theme which would break the feature.
Let me know if you found something.
Have a nice day!
Regards.
Hi @hwk-fr,
Thanks for the quick reply. I’ve done some testing on my end.
Could it be that one of the relationship fields being inside a group might be bugging? I’ve tested it on testing and it works fine, but when I start moving things into a group it seems to bug out.
Any other way I can debug this or see what’s going on in the background?
Best,
DaveJust did a bit more testing; as soon as I pull the relationship field out of the group it seems to work as expected.
Is this a bug or intended behaviour?Hello,
The Bidirectional Setting works in Groups, on one side, the other, or both sides. Here is a video showing it in action.
If you cannot make it work correctly within a Group, I would recommend to follow the steps described above to isolate the issue, as you might have some custom code/third party plugin compatibility issue.
In all cases, it’s always handy to have a blank WP Install with ACF + ACF Extended only with a native WP theme available. So you can easily test features like this one, and check if a behavior is a bug from ACF/ACFE or just a compatibility issue with a custom code.
Hope it helps!
Have a nice day!
Regards.
Hi @hwk-fr,
I’ve done some additional testing, the issue seems to arise when there is another field in the group before the relationship field. Moving that field (“Title”) after the relationship suddenly seems to make it work.
I haven’t tested this on a fresh install, but the issue seems consistent.
Json export of my setup below:
– CPT: Board Members
– Page: Main Course[ { "key": "group_6450f55d4e1ec", "title": "CPT - Board Members", "fields": [ { "key": "field_6450f55d4f57a", "label": "Profile picture", "name": "image", "aria-label": "", "type": "image", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "uploader": "", "return_format": "array", "acfe_thumbnail": 1, "min_width": 600, "min_height": 600, "min_size": "", "max_width": "", "max_height": "", "max_size": "", "mime_types": "", "preview_size": "medium", "library": "all" }, { "key": "field_6450f55d4f57f", "label": "Job title", "name": "job_title", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "maxlength": "", "placeholder": "", "prepend": "", "append": "" }, { "key": "field_6450f58f7f918", "label": "Courses", "name": "rel_courses", "aria-label": "", "type": "relationship", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "post_type": [ "courses" ], "post_status": "", "taxonomy": "", "filters": [ "search" ], "return_format": "id", "acfe_bidirectional": { "acfe_bidirectional_enabled": "1", "acfe_bidirectional_related": [ "field_644258fde7af9" ] }, "min": "", "max": "", "elements": [ "featured_image" ] } ], "location": [ [ { "param": "post_type", "operator": "==", "value": "boardmembers" } ] ], "menu_order": 0, "position": "normal", "style": "default", "label_placement": "left", "instruction_placement": "label", "hide_on_screen": [ "the_content", "featured_image" ], "active": true, "description": "", "show_in_rest": 0, "acfe_display_title": "", "acfe_autosync": [ "json" ], "acfe_form": 0, "acfe_meta": "", "acfe_note": "" }, { "key": "group_644254e1899f8", "title": "Page: Main Course", "fields": [ { "key": "field_64425bd3815fe", "label": "General introduction", "name": "general_introduction", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_64425ced81605", "label": "Course status", "name": "course_status", "aria-label": "", "type": "select", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "choices": { "default": "Default", "last-seats": "Last seats", "fully-booked": "Fully booked", "finished": "Finished" }, "default_value": "default", "return_format": "value", "multiple": 0, "allow_null": 0, "ui": 0, "ajax": 0, "placeholder": "", "allow_custom": 0, "search_placeholder": "" }, { "key": "field_6451164b8d742", "label": "Type", "name": "type", "aria-label": "", "type": "checkbox", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "choices": { "onsite": "On-site", "online": "Online" }, "default_value": [ "onsite" ], "return_format": "value", "allow_custom": 0, "layout": "horizontal", "toggle": 0, "save_custom": 0, "custom_choice_button_text": "Add new choice" }, { "key": "field_64425bd3815ff", "label": "Intro text", "name": "intro_text", "aria-label": "", "type": "wysiwyg", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "tabs": "all", "toolbar": "basic", "media_upload": 0, "delay": 0 }, { "key": "field_64425cca81604", "label": "Brochure download", "name": "brochure_download", "aria-label": "", "type": "file", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "uploader": "", "return_format": "array", "min_size": "", "max_size": "", "mime_types": "", "library": "all" }, { "key": "field_64425bd381600", "label": "Location pretty name", "name": "location", "aria-label": "", "type": "textarea", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "acfe_textarea_code": 0, "maxlength": "", "rows": 2, "placeholder": "", "new_lines": "" }, { "key": "field_64425c5a81602", "label": "Start date", "name": "start_date", "aria-label": "", "type": "date_picker", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "display_format": "d\/m\/Y", "return_format": "d\/m\/Y", "first_day": 1 }, { "key": "field_64425c8d81603", "label": "End date", "name": "end_date", "aria-label": "", "type": "date_picker", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "display_format": "d\/m\/Y", "return_format": "d\/m\/Y", "first_day": 1 } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_644254e1a6abf", "label": "Programme", "name": "programme", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_64425541a6ac0", "label": "Intro text", "name": "intro_text", "aria-label": "", "type": "wysiwyg", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "tabs": "all", "toolbar": "basic", "media_upload": 0, "delay": 0 }, { "key": "field_64425565a6ac1", "label": "Location", "name": "location", "aria-label": "", "type": "google_map", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "center_lat": "", "center_lng": "", "zoom": "", "height": 300 }, { "key": "field_644255e5a6ac2", "label": "More info", "name": "more_info", "aria-label": "", "type": "textarea", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "acfe_textarea_code": 0, "maxlength": "", "rows": 3, "placeholder": "", "new_lines": "br" } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_64425706e7132", "label": "Who should attend?", "name": "who_should_attend", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_64425728e7136", "label": "Title", "name": "title", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "Who should attend?", "maxlength": "", "placeholder": "", "prepend": "", "append": "" }, { "key": "field_64425706e7133", "label": "Intro text", "name": "intro_text", "aria-label": "", "type": "textarea", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "acfe_textarea_code": 0, "maxlength": "", "rows": "", "placeholder": "", "new_lines": "" }, { "key": "field_64425706e7135", "label": "Image", "name": "image", "aria-label": "", "type": "image", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "uploader": "", "return_format": "id", "acfe_thumbnail": 0, "min_width": "", "min_height": "", "min_size": "", "max_width": "", "max_height": "", "max_size": "", "mime_types": "", "preview_size": "medium", "library": "all" } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_644258097b9fe", "label": "Large image", "name": "large_image", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_644258097ba01", "label": "Image", "name": "image", "aria-label": "", "type": "image", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "uploader": "", "return_format": "id", "library": "all", "acfe_thumbnail": 0, "min_width": "", "min_height": "", "min_size": "", "max_width": "", "max_height": "", "max_size": "", "mime_types": "", "preview_size": "medium" } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_64425834ed425", "label": "Fee", "name": "fee", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_64425834ed426", "label": "Title", "name": "title", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "Fee", "maxlength": "", "placeholder": "", "prepend": "", "append": "" }, { "key": "field_64425834ed427", "label": "Intro text", "name": "intro_text", "aria-label": "", "type": "textarea", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "acfe_textarea_code": 0, "maxlength": "", "rows": "", "placeholder": "", "new_lines": "br" }, { "key": "field_64425834ed428", "label": "Course fee", "name": "course_fee", "aria-label": "", "type": "repeater", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "acfe_repeater_stylised_button": 0, "layout": "table", "pagination": 0, "min": 0, "max": 0, "collapsed": "", "button_label": "Add Row", "rows_per_page": 20, "sub_fields": [ { "key": "field_64425864ed429", "label": "Fee name", "name": "fee_name", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "maxlength": "", "placeholder": "", "prepend": "", "append": "", "parent_repeater": "field_64425834ed428" }, { "key": "field_64425876ed42a", "label": "Fee", "name": "fee_name_copy", "aria-label": "", "type": "number", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "2.750", "min": "", "max": "", "placeholder": "", "step": "", "prepend": "€", "append": ",-", "parent_repeater": "field_64425834ed428" } ] } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_645cccbc3d6ad", "label": "Course board", "name": "course_board", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_644258fde7af9", "label": "Select people", "name": "rel_select_people", "aria-label": "", "type": "relationship", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "post_type": [ "boardmembers" ], "post_status": "", "taxonomy": "", "filters": [ "search" ], "return_format": "id", "acfe_bidirectional": { "acfe_bidirectional_enabled": true, "acfe_bidirectional_related": [ "field_6450f58f7f918" ] }, "min": "", "max": "", "elements": [ "featured_image" ] }, { "key": "field_644258fde7af7", "label": "Title", "name": "title", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "Course board members", "maxlength": "", "placeholder": "", "prepend": "", "append": "" } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_644259c5857ac", "label": "Downloads & brochures", "name": "downloads_brochures", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_644259c5857ad", "label": "Title", "name": "title", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "Downloads & brochures", "maxlength": "", "placeholder": "", "prepend": "", "append": "" }, { "key": "field_644259c5857ae", "label": "Documents", "name": "documents", "aria-label": "", "type": "repeater", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "acfe_repeater_stylised_button": 0, "layout": "table", "pagination": 0, "min": 0, "max": 0, "collapsed": "", "button_label": "Add Row", "rows_per_page": 20, "sub_fields": [ { "key": "field_64425a2d857b0", "label": "Pretty name", "name": "name", "aria-label": "", "type": "text", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "maxlength": "", "placeholder": "", "prepend": "", "append": "", "parent_repeater": "field_644259c5857ae" }, { "key": "field_644259ff857af", "label": "File", "name": "file", "aria-label": "", "type": "file", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "uploader": "", "return_format": "array", "min_size": "", "max_size": "", "mime_types": "pdf", "library": "all", "parent_repeater": "field_644259c5857ae" }, { "key": "field_64425a66161f6", "label": "Image", "name": "image", "aria-label": "", "type": "image", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "uploader": "", "return_format": "id", "acfe_thumbnail": 0, "min_width": "", "min_height": "", "min_size": "", "max_width": "", "max_height": "", "max_size": "", "mime_types": "", "preview_size": "thumbnail", "library": "all", "parent_repeater": "field_644259c5857ae" } ] } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_64425aa8bdded", "label": "Register", "name": "register", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_64425aa8bddee", "label": "Intro", "name": "intro", "aria-label": "", "type": "textarea", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "acfe_textarea_code": 0, "maxlength": "", "rows": 6, "placeholder": "", "new_lines": "br" }, { "key": "field_64425ad6bddf3", "label": "Note", "name": "note", "aria-label": "", "type": "textarea", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "default_value": "", "acfe_textarea_code": 0, "maxlength": "", "rows": 4, "placeholder": "", "new_lines": "br" } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" }, { "key": "field_64425aedbddf4", "label": "Testimonials", "name": "testimonials", "aria-label": "", "type": "group", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "layout": "row", "acfe_seamless_style": 0, "acfe_group_modal": 0, "sub_fields": [ { "key": "field_64425aeebddf6", "label": "Select testimonials", "name": "select_testimonials", "aria-label": "", "type": "relationship", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "acfe_save_meta": 0, "post_type": [ "testimonials" ], "post_status": "", "taxonomy": "", "filters": [ "search" ], "return_format": "id", "acfe_bidirectional": { "acfe_bidirectional_enabled": "1", "acfe_bidirectional_related": [ "field_645cc8bea6aa0" ] }, "min": "", "max": "", "elements": [ "featured_image" ] } ], "acfe_group_modal_close": 0, "acfe_group_modal_button": "", "acfe_group_modal_size": "large" } ], "location": [ [ { "param": "post_type", "operator": "==", "value": "courses" }, { "param": "page_type", "operator": "==", "value": "top_level" } ] ], "menu_order": 0, "position": "normal", "style": "seamless", "label_placement": "top", "instruction_placement": "label", "hide_on_screen": [ "the_content" ], "active": true, "description": "", "show_in_rest": 0, "acfe_display_title": "", "acfe_autosync": [ "json" ], "acfe_form": 0, "acfe_meta": "", "acfe_note": "" } ]
Hello,
I just tested your Field Groups, and it works fine on my end. Here is the video demo of my test.
An additional field such as Title being added before or after the field should have no impact on it. I really suspect some custom code or third party code incompatibility.
I would recommend to follow the steps describe in my first answer in order to isolate the issue. In all cases, you should be able to make it work on a clean WP install like I did.
Hope it helps!
Have a nice day!
Regards.
- The topic ‘Bidirectional fields not updating as expected’ is closed to new replies.