Bidirectional saving gets triggered by post preview, removes post object value
-
Hi,
I believe I ran into a bit of an edge case with bidirectional relationship.
To summarize, when previewing a post that has a
relationship
type field set to be bidirectional with apost object
type field, thepost object
field’s value gets replaced with a revision id of the post I just previewed (probably the revision that wordpress generates to show the preview). The revision then automatically gets deleted and mypost object
field ends up with an id that doesn’t exist.Here are the steps to reproduce this behaviour :
- Create 2 CPTs (we’ll call them “recipe” and “ingredient” for convenience). Make sure they are not using Gutenberg (the issue doesn’t seem to happen with Gutenberg enabled post types, maybe because preview is handled differently).
- On the recipe CPT, add a relationship field set to select ingredients.
- On the ingredients CPT, add a post object field set to select a single recipe.
- Create a recipe, and some ingredients.
- Edit the recipe, and add some ingredients in the relationship field and save.
- The bidirectional setting works as expected and the post object field in the ingredients gets updated accordingly.
- Now back in the recipe, do some changes (e.g. change the title and content), then don’t save but instead click the “Preview Changes” button. This should open a preview in a different tab.
- Now open one of the ingredient’s edit screen, the post object field should appear empty.
I believe what might be happening here is WordPress generates a revision for previewing, which triggers the bidirectional saving in said revision and overrides the value in the post object field of the ingredient with the id of that revision. Could be something else entirely but I thought it seemed like a logical explanation.
I’ve been able to reproduce this issue with the latest WP version (6.1.1), the latest ACF Pro (6.0.7) and the latest ACFE (0.8.9) using the Twenty Twenty-Three theme on a fresh WP install.
I hope it’s not too confusing as it’s a bit hard to explain this. Don’t hesitate to ask for more details if needed.
Best regards,
- The topic ‘Bidirectional saving gets triggered by post preview, removes post object value’ is closed to new replies.