How to make a filter using checkboxes on WordPress?

Hello, through trial and error I was able to make a no filter WordPress posts by tags. All the rules, but was left a trifle. You need to make the selection of tags using a checkbox and not using a selector, as it now stands. The problem is that due to the fact that I don't really know PHP, I am unable to do everything. Namely when I was doing that via a checkbox, I have displayed all the records have tags. Tried using the slug parameter, but what he has that is not present - without a difference. Total: we need to make sure that you could choose multiple options in the filter. It is a regular filter, but not do it for me. Most likely, the solution is very close)
function.php
posts_filters function(){
 $args = array(
 'orderby' => 'date',
 'order' => $_POST['date']
);

 if( isset( $_POST['categoryfilter'] ) )
 $args['tax_query'] = array(
array(
 'taxonomy' => 'post_tag',
 'slag' => 'okna',
 'field' => 'id',
 'terms' => $_POST['categoryfilter']
)
);

 if( isset( $_POST['check'] ) && $_POST['check'] == 'on' )
 $args['tax_query'] = array(
array(
 'taxonomy' => 'post_tag',
 'slag' => 'okna',
 'field' => 'id',
 'terms' => $_POST['check']
)
);

 $query = new WP_Query( $args );

 if( $query->have_posts() ) :
 echo '<div class="row">
 <div class="col">
 <div class="allLogoBrands">';
 while( $query->have_posts() ): $query->the_post();
 echo '<div><a href="' . get_permalink( $query->post->ID ) . '">' . the_post_thumbnail() . '</a></li>';
endwhile;
 echo '</div>

</div>
</div>
</div>';
wp_reset_postdata();
 else :
 echo 'no Records found';
endif;

die();
}
add_action('wp_ajax_customfilter', 'posts_filters');
add_action('wp_ajax_nopriv_customfilter', 'posts_filters');

page.php
<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="post-date-filter">
<?php
 if( $terms = get_terms( 'post_tag', 'orderby=name' ) ) :
 echo '<select name="categoryfilter"><option>Select category...</option>';
 foreach ( $terms as $term ) :
 echo '<option value="' . $term->term_id . '">' . $term->name . '</option>';
endforeach;
 echo '</select>';
endif;
?>
 <label><input type="checkbox" name="check" /> Okna</label>


 <button>Apply filter</button>
 <input type="hidden" name="action" value="customfilter">
</form>
 <div id="filtering-results"></div>

jQuery(function($){
$('#post-date-filter').submit(function(){
 var filter = $('#post-date-filter');
$.ajax({
url:filter.attr('action'),
 data:filter.serialize(), // form data
 type:filter.attr('method'), // POST
 beforeSend:function(xhr){ filter.find('button').text('Apply filter...'); },
 success:function(data){ filter.find('button').text('Apply filter'); $('#filtering-results').html(data); }
});
 return false;
});
 });


Part of the code was taken from here CODE
A couple of screenshots of the page itself
5e28ec721774e259215515.png
5e28ec77508b8290616977.png
5e28ec7c3850a691460358.png
April 4th 20 at 13:25
1 answer
April 4th 20 at 13:27
If you need checkboxes, why would you bring as a select? Solve the problem step by step and start with the right layout.
The fact that the code was originally taken with the selector in that and a problem that can't alter the checkboxes for all breaks - hilda.Lesch29 commented on April 4th 20 at 13:30

Find more questions by tags WordPressWooCommerce