Relationships + Conditional Logic

Support MB Relationships Relationships + Conditional Logic

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #48486
    Tanja KropfTanja Kropf
    Participant

    Is there a way to show/hide the relationships fields with conditional logic?

    #48487
    Tanja KropfTanja Kropf
    Participant

    I 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;
    } );

    #48494
    PeterPeter
    Moderator

    Hello Tanja,

    Yes, it is possible. Each relationship meta box has an ID: {$relationship_id}_relationships_from and {$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-page is the relationship ID, screenshot https://ibb.co/n8QV8FCQ

    #48498
    Tanja KropfTanja Kropf
    Participant

    I 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;
    });
    #48503
    PeterPeter
    Moderator

    Hello,

    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'],
        ];
    #48506
    Tanja KropfTanja Kropf
    Participant

    Looks like I missed those. But just added them and no change.

    #48507
    PeterPeter
    Moderator

    Hello,

    Please share some screenshots of the relationship settings and the relationship box on the editing page. I will help you check the issue.

    #48508
    Tanja KropfTanja Kropf
    Participant

    Sure. Here you go: https://imgur.com/a/i3Kk8Xo

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