Support » Plugin: ACF Post-2-Post » Relationship not updated on delete

  • rhkittredge



    I’m finding that when I add a post that contains a bidirectional relation, your plugin does properly add the post to the other relationship cpt field. But when I delete a post (within the WP dashboard), that post is not removed from the other relationship. In my case I’m using Toolbox and the Timber Posts module still shows posts from the relationship field, which are actually deleted.

    If I go into the WP dashboard and edit the particular record containing the other relationship and just click Update, the post no longer shows in the Timber Posts. It seems during the update process the relationship field is updated with only published posts.

    So it seems as if this statement in your documentation: “If a post is removed from a relationship then the post being removed will also be updated to remove the relationship to the post being edited.” is not working for some reason.

    Using ACF 5.8.9 and 1.5.2 of your plugin if that makes any difference.

    Thanks for any assistance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Huebner


    This is the way that this plugin has always worked. The relationship fields are only updated when a post is updated and not when a post is deleted.

    This plugin works on the acf/update_value hook of relationship and post object fields. This allows my to know exactly what field is being updated.

    When a post is deleted there isn’t any way to know that there is a relationship field used on that post. One would need to get all the field groups used on that post and loop over all of the fields to find any post object or relationship fields and then do a search each post on the other end to remove them.

    Deleting a post is not the same as editing another post and removing it from the relationship field.

    Anyway, this is not something that will be added to this plugin. There are several reasons for this.

    One reason is is that if you use the ACF function get_field() to get the relationship field it will not return posts that have been deleted, they are filtered out, as you noticed when editing a post.

    In addition to this if you return just the ID values for a relationship field if you use the WP function get_post() or any WP function that works on the post ID it will also not return posts that have been deleted.

    This plugin also does nothing different than what ACF does. Create a relationship field that is not bidirectional and add a post to it, then go and delete that post. Checking the database you will find that the post ID is still present in the value of the relationship field where it was added. You would have the same issue with or without using this plugin. There is no mechanism in ACF to check relationship type fields on posts when a post is deleted.

    Sorry, I don’t have an answer for you in this case. The tool or other plugin that is being used to show the ACF field value would need to make sure the posts exist before attempting to show them and this would be true with or without the use of this plugin being active.

    Thread Starter rhkittredge


    Got it. Thank you for the explanation. I think what threw me was the line in your doc about if a post is removed from a relationship it’s removed from the other too. But I now understand that removing a post from a relationship isn’t the same as deleting. It just seemed that since your plugin worked when creating/updating a post it would also work when deleting. But I understand why it doesn’t. Perhaps you should add some clarification in the documentation about that.

    I’ll just add some code to check whether a post is deleted or not before it’s output on the page. I think the times this will happen are few and far between but still needs to be accounted for.

    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.