Relationships + Conditional Logic
Support › MB Relationships › Relationships + Conditional Logic
- This topic has 8 replies, 2 voices, and was last updated 5 months ago by
Peter.
-
AuthorPosts
-
June 22, 2025 at 11:33 PM #48486
Tanja Kropf
ParticipantIs there a way to show/hide the relationships fields with conditional logic?
June 22, 2025 at 11:48 PM #48487Tanja Kropf
ParticipantI tried this but it didn't work:
add_filter( 'rwmb_outside_conditions', function( $conditions ) {
$conditions['.listing-to-listing-wrapper'] = [
'hidden' => ['listing_package', 'free'],
];
return $conditions;
} );June 23, 2025 at 11:22 PM #48494Peter
ModeratorHello Tanja,
Yes, it is possible. Each relationship meta box has an ID:
{$relationship_id}_relationships_fromand{$relationship_id}_relationships_to. You can use the ID in the outside condition code to show/hide the relationship meta box.For example:
add_filter( 'rwmb_outside_conditions', function( $conditions ) { $conditions['#post-to-page_relationships_to'] = [ 'hidden' => ['listing_package', 'free'], ]; return $conditions; } );post-to-pageis the relationship ID, screenshot https://ibb.co/n8QV8FCQJune 23, 2025 at 11:44 PM #48498Tanja Kropf
ParticipantI added this code below per your instructions, but it still did not hide.
add_filter( 'rwmb_outside_conditions', function( $conditions ) { $conditions['listing-to-event_relationships_to'] = [ 'hidden' => ['listing_package', 'free'], ]; $conditions['listing-to-listing_relationships_to'] = [ 'hidden' => ['listing_package', 'free'], ]; $conditions['event-to-event_relationships_to'] = [ 'hidden' => ['listing_package', 'free'], ]; return $conditions; });June 24, 2025 at 9:37 PM #48503Peter
ModeratorHello,
Did you add the hash character (#) before the relationship ID as I write down in the previous reply? For example:
$conditions['#listing-to-event_relationships_to'] = [ 'hidden' => ['listing_package', 'free'], ];June 24, 2025 at 11:06 PM #48506Tanja Kropf
ParticipantLooks like I missed those. But just added them and no change.
June 25, 2025 at 8:21 AM #48507Peter
ModeratorHello,
Please share some screenshots of the relationship settings and the relationship box on the editing page. I will help you check the issue.
June 26, 2025 at 5:29 AM #48508Tanja Kropf
ParticipantSure. Here you go: https://imgur.com/a/i3Kk8Xo
June 26, 2025 at 8:10 PM #48509Peter
ModeratorHello,
I don't see any issues based on your screenshot. Please share your site credentials by submitting this contact form https://metabox.io/contact/
I will take a look. -
AuthorPosts
- You must be logged in to reply to this topic.