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:

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

The default LayersWP widget only lets you choose one specific category to show, and 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(
                '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
        ); ?>
<?php } // if !is_wp_error ?>

How exactly do I give users the option to select multiple categories in this builder widget, and then save the categories that are selected?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.