0

I have implemented a custom post type called "Portfolio" and I have included the taxonomy: category with 3 categories: Category1, Category2 & Category3

I have created a filter form to filter posts based on category as follows at the top of my archive-portfolio.php file:

<form>
    
    <?php 
    $terms = get_terms([
        'taxonomy' => 'category'
    ]);
    
    foreach ($terms as $term) : ?>
        <label>
            <input type="checkbox"
                   name="category[]"
                   value="<?= $term->slug ?>"
                   <?= checked( isset($_GET['category']) && in_array($term->slug, $_GET['category']) )?>
                   onClick="this.form.submit()"/>
            
            <?= $term->name ?>
        </label>
    
    <?php endforeach; ?>
    
</form>

This successfully displays all 3 categories correctly as selectable checkboxes and when I select one, it reloads the page and the option is selected (so the value is being passed to the page) BUT, the results are not being filtered.

Are there any pre-requisites for this to work?

0

Your Answer

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