How to hide Metabox group according to taxonomy selection?

Support MB Conditional Logic How to hide Metabox group according to taxonomy selection?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6331
    xoomservexoomserve
    Participant

    Hi,

    First, Thank you for all the efforts and education we have here.
    I'm working in Realestate website and I want to do the following:
    1- Drop down menu with the Properties type (Rent, Sale)
    2- Once selecting the type (Rent/Sale) the related field group will show.

    Please note, The properties type is Taxonomy and The related field are just fields.

    I hope you can help me understand as I'm not developer but I can easy understand what you want me to do.

    Thank you in advance.
    Tariq

    #6344
    Tan NguyenTan Nguyen
    Participant

    Dear xoomserve,

    Here is the example which I've created with MB Builder:

    
    add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
    
    function your_prefix_register_meta_boxes( $meta_boxes ) {
    
        $meta_boxes[] = array (
          'id' => 'untitled-metabox-2',
          'title' => 'Untitled Metabox',
          'pages' =>   array (
             'post',
             'page',
          ),
          'context' => 'normal',
          'priority' => 'high',
          'autosave' => false,
          'fields' =>   array (
             
            array (
              'id' => 'properties',
              'type' => 'taxonomy',
              'name' => 'Properties',
              'taxonomy' => 'product_type',
              'field_type' => 'select',
            ),
             
            array (
              'id' => 'another_text_field',
              'type' => 'text',
              'name' => 'Text Field',
              'visible' =>       array (
                'when' =>         array (
                  array (
                     'taxonomy_2',
                     '=',
                     '4',
                  ),
                ),
                'relation' => 'and',
              ),
            ),
          ),
        );
    
        return $meta_boxes;
    }
    

    Basically, you can register your taxonomy field and another field normally. And then, in related field (Text in this example), just define your conditional logic:

    
    'visible' => ['your_taxonomy_id', '=', 'taxonomy_value']
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘How to hide Metabox group according to taxonomy selection?’ is closed to new replies.