CMB2 / cmb2-attached-posts

Custom field for CMB2 for attaching posts to a page.
GNU General Public License v2.0
135 stars 62 forks source link

Removing deleted posts from already attached list #42

Open nadinezein opened 7 years ago

nadinezein commented 7 years ago

Thank you for this great plugin. I didn't find this but not sure if its similar to "bidirectional relationship".

Is there a way to exclude the posts that have been originally deleted from the already attached list, without needing to resave or remove them manually?

example: We have the following posts: postA, postB, postC Under Related Posts (using cmb2 attached posts) for postA I have saved postB and postC. After doing so I delete postC in the future. Can postC be excluded from postA Related Posts both in the front and back end?

claytoncollie commented 7 years ago

+1 on this one. Draft would be good to remove from this list as well. Or at least have a filter to specify which type of post state you want to show on front and backend

websitegenii commented 2 years ago

I agree here, this is causing issues for a site we have. We have attached "Providers" to each Service page which is a lot of services pages. Though when removing them the saved data for this still includes the ID of the post type.

I think I can fix this by checking if it's empty in my own loop but ideally this data wouldn't be passed at all once the original post is deleted.

tw2113 commented 2 years ago

One of the big issues I can think of with this is knowing what other posts have a given ID saved as meta, so that it can be somehow removed. Otherwise, it's going to be a case of checking for every row in the postmeta database to try and find the ID, and also making sure that it's also a post that is actually using the intended meta key.

A lot of complexities the more I think about it.

websitegenii commented 2 years ago

I've fixed our existing site for now by calling this field but when I loop through the ID's I am checking if it's publish status. This allows me to use continue; to skip the CPT that's not published.