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

Reciprocal Relationships? #55

Open forwardtrends opened 6 years ago

forwardtrends commented 6 years ago

Is there a way to use the relationship both ways (reciprocal)?

For instance lets say I have 2 CPTs - cars and car parts.

So when editing a car, you can drag the part or parts to attach them.

When editing a part, is there a way I can see and manage all the cars that are already attached to it?

I can write a function to do this - just looking for a shortcut if it's already built in somehow. Thanks

jtsternberg commented 6 years ago

It is not currently a thing, but is something I've been planning to do/document for ages. Did you build something?

forwardtrends commented 6 years ago

Just on the front end by querying postmeta for the related post IDs

$rows = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE (meta_key= 'yourkey_attached_parts' ANDmeta_valueLIKE '%".$current_post_id."%')");

edvind commented 6 years ago

This would be a fantastic feature to have. +1

tnorthcutt commented 5 years ago

This seems to maybe be a duplicate of https://github.com/CMB2/cmb2-attached-posts/issues/28, or at least relate