prevent duplicate relationship
Support › MB Relationships › prevent duplicate relationshipResolved
- This topic has 7 replies, 2 voices, and was last updated 2 days, 23 hours ago by
aryanraj.
-
AuthorPosts
-
February 24, 2026 at 4:39 PM #49767
aryanraj
ParticipantHi, i have a relationship from pictures to books. the relationship is 1:1 Reciprocal relationship. i want to prevent assigning a pictures post (type). to a different book. I basically want to hide the already linked relation post so it not get reassigned to different.
i see there is Query args, wonder if anyway we can exclude those already have relationship assigned.
Thanks.
February 25, 2026 at 10:28 PM #49771Peter
ModeratorHello,
Thanks for reaching out.
There isn't an option to exclude a post from the list if it has a relationship. I will inform the development team to consider supporting this feature in future updates.
Regarding the reciprocal, it will work if you have the relationship for the same post type. Like from
picturestopictures. Following the documentation https://docs.metabox.io/extensions/mb-relationships/#relationship-settingsMarch 21, 2026 at 12:05 AM #49822aryanraj
ParticipantI have tried few things and i am not able to find the right hook, is there any way to pass a new filter to change the query? currently it list all posts and i wonder if i can overwrite this query. i am looking for the right hook.
March 21, 2026 at 9:06 AM #49825Peter
ModeratorHello,
We are working on this feature, you can check it in the pull request https://github.com/wpmetabox/mb-relationships/pull/94/changes
If you are familiar with coding, feel free to make the changes on your site to see if it helps.March 21, 2026 at 11:33 AM #49827aryanraj
ParticipantThanks, i see the pull request is still open for 3 weeks, will it be merged anytime soon?
November 3, 2026 at 3:06 PM #50262aryanraj
ParticipantHi, how to set this via gui? and code?
<?php add_action( 'mb_relationships_init', '' ); function () { MB_Relationships_API::register( [ 'title' => 'pictures_to_conference', 'id' => 'pictures_to_conference', 'object_type' => 'post', 'post_types' => ['post'], 'priority' => 'high', 'style' => 'default', 'closed' => false, 'class' => '', 'prefix' => '', 'revision' => false, 'settings_page' => [], 'from' => [ 'post_type' => 'pictures', 'field' => [ 'max_clone' => 1, 'add_new' => false, 'query_args' => [ 'mb_rel_filter' => 'pictures_to_conference', 'relationship_filter' => 'pictures_to_conference', ], ], 'admin_filter' => false, 'has_one_relationship' => true, ], 'modified' => 1770529540, 'reciprocal' => true, 'to' => [ 'post_type' => 'conference', 'object_type' => 'post', 'field' => [ 'add_new' => false, 'max_clone' => 1, ], 'admin_filter' => false, 'has_one_relationship' => true, ], 'context' => 'normal', ] ); }November 3, 2026 at 10:48 PM #50263Peter
ModeratorHello,
That code using
has_one_relationshipis correct. You can refer to the documentation https://docs.metabox.io/extensions/mb-relationships/#using-codeIn the builder, you can enable the option "Has one relationship" when editing/creating the relationship. Please check this screenshot https://ibb.co/CKj5nDb6
Thanks.
November 3, 2026 at 11:10 PM #50264aryanraj
ParticipantThanks, seems like i already enabled it and forget to reload for recheck. working.
-
AuthorPosts
- You must be logged in to reply to this topic.