Custom Fields
Re-Envisioned
Support General Custom Select Tree

  • Creator
    Topic
  • #5574
    alpha.media
    Participant

    Without using the taxonomy or post field type, can the checkbox be made into a tree similar to how the taxonomy select boxes work? Reason is I need to create a checkbox meta box that has the ability to select a parent checkbox which will select all the children in that checkbox tree. Need it to be able to select groups of options at once.

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #5690
    Anh Tran
    Keymaster

    Yes, you can do that. Here is the sample code:


    <?php
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
    $meta_boxes[] = array(
    'title' => 'Test',
    'fields' => array(
    array(
    'type' => 'select_tree', // or checkbox_list
    'id' => 'cb',
    'name' => 'Hierarchical checkboxes',
    'options' => array(
    array( 'value' => 'value1', 'label' => 'label 1' ),
    array( 'value' => 'value2', 'label' => 'label 2' ),
    array( 'value' => 'sub1', 'label' => 'Sub 1', 'parent' => 'value1' ),
    array( 'value' => 'sub2', 'label' => 'Sub 2', 'parent' => 'value1' ),
    ),
    'flatten' => false,
    ),
    ),
    );
    return $meta_boxes;
    } );

    view raw

    demo.php

    hosted with ❤ by GitHub

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Select Tree’ is closed to new replies.