Selecting multiple categories from a custom post type to be displayed in LayersWP builder widget

I am currently developing a LayersWP child theme and have registered a portfolio custom builder widget.

In this widget i would like users to be able to select the categories that they want shown. For example:

Read More

“A user has multiple portfolio items. One in the category”Art”, one in the category “Design” and one in the category “Devolpment”. On the homepage the user only wants to show portfolio items in the category “Design” and “Art”.

The default LayersWP widget only lets u choose one specific category to show, it’s not possible to select multiple categories. I would like to build this into my widget but can’t really find anything about it in the LayersWP docs.

I am kind of struggling on how to save the categories that are selected.

Currently this is my code markup:

 $terms = get_terms( $this->taxonomy );
                    if( !is_wp_error( $terms ) ) { ?>
                        <p class="layers-form-item">
                            <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php echo __( 'Category to Display' , LAYERS_THEME_SLUG ); ?></label>
                            <?php $category_options[ 0 ] ="All";
                            foreach ( $terms as $t ) $category_options[ $t->term_id ] = $t->name;
                            echo $this->form_elements()->input(
                                array(
                                    'type' => 'select',
                                    'name' => $this->get_field_name( 'category' ) ,
                                    'id' => $this->get_field_id( 'category' ) ,
                                    'placeholder' => __( 'Select a Category' , LAYERS_THEME_SLUG ),
                                    'value' => ( isset( $categories ) ) ? $categories : NULL ,
                                    'options' => $category_options
                                ) 
                            ); ?>
                        </p>
                    <?php } // if !is_wp_error ?>

So how exactly do i give users the option to select multiple categories in this builder widget. And then save the categories that are selected?

Any help is appreciated

Related posts

1 comment

  1. As per your requirement, You’ll use checkboxs. It was already used in layerswp post widget.

    For reference visit: https://github.com/Obox/layerswp/blob/master/core/widgets/modules/post.php#L524

    You’ll also contact on Layerswp support forum. You’ll found all existing question which helps you.

    Same reference http://docs.layerswp.com/forums/question/how-to-set-a-new-field-type-of-multi-select-in-to-grab-the-category-value-in-layers-builder-widgets/

Comments are closed.