acf-post2post icon indicating copy to clipboard operation
acf-post2post copied to clipboard

Relationship field gets emptied when using 'Preview' of a post

Open atomtigerzoo opened this issue 4 years ago • 3 comments

Hi! I have a hard time to reproduce this bug. We have a 1to1 relationship between a post and a custom typ post. It works correctly, so that when one side saves/updates/deletes the relationship, it gets updated inside the other post. So far so good 👍

But when saving and previewing the post a few times the relationship field in the backend (and so the database) will get emptied and the relationship is deleted. Most times it will happen when we have post already written and saved (published or outstanding doesnt matter) and the use the 'Preview' button of Wordpress. Not every time, but sometimes.

I tried to debug the saving process somehow, but cannot find out how and where this could happen or fail 🤷‍♀️

Any ideas what could be buggy or goes wrong?

Fields have the same name, both are top level and not nested inside repeaters/flexibles. Latest WP, latest ACF, latest P2P. Just using this filter to overwrite values because we only use one (from the docs):

add_filter('acf-post2post/overwrite-settings', function($settings) {
  $settings['product_test_relationship'] = [
    'overwrite' => true,
    'type' => 'first'
  ];
  return $settings;
});```

atomtigerzoo avatar Aug 18 '21 14:08 atomtigerzoo

My guess here is that this plugin is suffering from a similar problem that others report of the ACF forum to do with ACF fields not being saved when using preview. This plugin depends on the acf/update_value hook being triggered. If this hook is triggered then this plugin is finding now value in the field, or an empty value is being passed to the filter in this plugin. I don't have any idea what would cause that. To be honest, I don't even know where to start looking.

Hube2 avatar Aug 18 '21 17:08 Hube2

Thank you for your comment! As this does not happen all the time, more like sometimes and not reproducable it is indeed very hard to catch or show. But yes, it looks like the value from the P2P field is not saved/updated or wrongly saved/updated. All the other fields - we have about 5 with the default post and 30 with the CTP - get saved correctly and not deleted.

I will keep an eye on the issue. Maybe someone else finds this too and has brilliant idea on how to catch this bug 😎

Thank you for your time and have a nice day!

atomtigerzoo avatar Aug 19 '21 07:08 atomtigerzoo

If you can give me steps that will consistently reproduce the issue I will look into it, but as you say, it's very hard to find something when otherwise.

Hube2 avatar Aug 19 '21 12:08 Hube2