• Resolved nauran81

    (@nauran81)


    I sent this to ACF not realizing this feature was actually an ACF:Extended ability.

    I am running ACF Pro - Version 5.10.2
    and Advanced Custom Fields: Extended - Version 0.8.8.5
    
    I have setup a relationship between 2 post types: products and Finance & Promotions Options
    
    Product's ACF relationship field is here - https://share.getcloudapp.com/bLuqlExb
    Fin&Promo Option's ACF relationship field is here - https://share.getcloudapp.com/04ux6BEw
    ...both are bi-directional.
    
    So, we set 2 of the Fin&Promo Option entries to be related to the same product, the S220:
    "No Interest if Paid in Full within 12 months on New John Deere S200 Series Lawn Tractors" - https://share.getcloudapp.com/Wnu0mOZq
    "4.90% APR fixed rate for 60 Months on New John Deere S200 Series Lawn Tractors" - https://share.getcloudapp.com/X6ulKpKW
    
    But, when we go into the S220 product, only 1 Fin&Promo Option is showing:
    https://share.getcloudapp.com/Apu9v4lg
    
    We have to be able to set the relationship at the Fin&Promo Option versus each individual Product...and our hope was that bidirectional relationships would work for any number of related options to a product.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I just tested it, and the bidirectional works fine here. Have you tried to remove the “S220” from the “4.90% APR fixed rate” relationship, save the post, re-add it and save the post again?

    Also can you try to add an another item, just to make sure you don’t have specific rules that would disallow the field update on that post?

    You could also try to add an item directly from the “S220” post, and make sure the relationship is correctly added from there.

    Thanks in advance,

    Regards.

    Thread Starter nauran81

    (@nauran81)

    Hi Konrad,

    So actually, what we discovered yesterday is when manually added, it works.

    BUT we were using a post duplicator plugin to duplicate entries that had existing bi-directional relationship fields filled in.

    The plugin in question we were using: Duplicate Page Version 4.4.1 | By mndpsingh287

    So the original FinanceOption entry related to multiple products works fine…but when we duplicate the entry to a new FinanceOption for the same set of products, the new one does not seem to “update” the related Product’s Bi-direction related field of Finance Options to add the duplicated Finance Option.

    …does that make sense?

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Well now that makes sense, yes. The Bidirectional Setting use native ACF hooks acf/update_value in order to establish the bidirectional values.

    When using a third-party plugin to duplicate a post, it will most likely use native WordPress functions like add_post_meta(), to add metadata that were set in the original post. Those native WordPress functions bypass the ACF logic, and thus never trigger ACF Extended Bidirectional saving process.

    Unfortunately there’s not many solutions here, apart from running a script that will force to re-update meta values (and trigger the bidirectional logic), like explained in the Bidirectional Setting documentation.

    Note that saving the new post manually from the WordPress admin will not trigger the update process if no values were changed. In fact, the Bidirectional Setting has been designed to be only save changes, when a new value has been added or when a previously set value has been removed, to optimize performance and avoid saving again and again multiple values everytime the admin save a post.

    If you prefer force the update from the admin, then you have to edit your new post, remove all values in the Relationship field, save the post, re-add new values and save the post again.

    Hope it helps!

    Regards.

    Thread Starter nauran81

    (@nauran81)

    Hey Konrad,

    Thanks for confirming all this.

    So to clarify, our options are:

    1. setup the code snippet to force to re-update these specific bidirectional fields while being able to use the duplicate post/page plugins?
    If so, we’d have to setup a snippet for each created bi-direction field, yes?
    Lastly, does this situation affect other ACF fields other than bi-directional relationship fields?

    2. instead of using the code snippet, and after a duplication, we would have to go into the new post, remove all related posts from the field, save, then re-add them, and save…and this SHOULD update the other related post’s bi-direction field values?

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    To clarify:

    1. The “script” code snippet provided in the documentation will loop through all pages in the database and force the update of a specific bidirectional field (in the example, the field is named my_field). This script should be run only once, and removed when all posts are correctly updated.

    2. Instead of the “script” solution, an another way to update the values is to manually trigger the save from the Admin UI. I forgot to mention in my previous answer that there is a much simpler way to achieve that from the Admin UI.

    Instead of “remove values, save the post, re-add values, re-save the post…”, you can simply add this code in your theme’s functions.php file:

    add_filter('acfe/bidirectional/force_update', '__return_true');
    

    Then head over your duplicated post, and simply save the post. It will force the update of all bidirectional fields within that post.

    Once all your posts are correctly updated, you can then remove that code from your functions.php file to increase performance of normal saving process.

    I took the opportunity to update the documentation to add more details, and explain a little more these two solution. I hope it’s now more clear.

    Lastly, does this situation affect other ACF fields other than bi-directional relationship fields?

    I’ll try to not be too technical, but in theory, the problem of using a “Duplicate Post plugin which use native WordPress function instead of ACF update function” affect any ACF field that has a non-classical behavior outside of saving a metadata when updated (within the acf/update_value hook).

    The bidirectional setting is an edge-case tho, since 99% of ACF fields will simply update their own metadata (and not other posts), which is fine when using a Duplicate Post plugin that copy existing metadata.

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Bidirectional related fields between posts are not working correctly’ is closed to new replies.