How to set a new field “type” of “multi-select” in to grab the category value in Layers Builder Widgets?

Asked on July 23, 2015 in Development.

hello, I have some mistake.
I don’t now how to use field “type” of “multi-select”.
I try, but it not show right.
Who can help me? thanks

bk_cbg_ct Developer
Reply
  • Possible Answers to Your Question:

  • 1 Answer(s)
    Answered on August 24, 2015. Best answer

    Hi there,

    If you check out our post widget for reference, you should be able to do it the same. It is more difficult when you want to allow for choosing specific categories or multiple categories. In our StoreKit plugin, for example, our Category widget uses a type of hidden, then grabs  that instance of the category id:

    <?php if( isset( $category_ids ) && '' != $category_ids ){
                            foreach ( explode( ',', $category_ids ) as $category_id ) {
                                $term = get_term( $category_id, $this->taxonomy );
                                $select_terms[] = array( 'id' => $term->term_id, 'text' => esc_attr( $term->name ) );
                            }
                        } ?>
    <p class="layers-form-item">
                            <label><?php _e( 'Select Which Categories to Display' , 'layers-storekit' ); ?></label>
                            <?php echo $this->form_elements()->input(
                                array(
                                    'type' => 'hidden',
                                    'name' => $this->get_field_name( 'category_ids' ),
                                    'id' => $this->get_field_id( 'category_ids' ),
                                    'data' => array(
                                                'woocommerce-column-category-ids' => $this->number,
                                                'placeholder' => __( 'eg. "T-Shirts"' , 'layers-storekit' ),
                                                'terms' => ( isset( $select_terms ) ? json_encode( $select_terms ) : false )
                                            ),
                                    'value' => ( isset( $category_ids ) ? $category_ids : NULL )
                                )
                            );?>
     </p>
    

    https://github.com/Obox/layerswp/blob/master/core/widgets/modules/post.php#L542

    Please see the following:

    https://docs.layerswp.com/reference/input/

    https://docs.layerswp.com/development-tutorials-layers-builder-widgets/

    Vail Joy Layers Team
    Reply