I want to list articles that belong to several specific categories by selecting a check box.

Asked 1 months ago, Updated 1 months ago, 4 views

I would like to get this URL by selecting it by check box

my domain/category/slugA+slugB

Currently, I have the following code, but the URL I got is like this (%2b stands for +).

my domain/?category=SlugA%2bSlugB

Code provided

<form class="cat-search" action="<?php bloginfo('url');?>">
  <input type="checkbox" value="SlugA" id="cat0" class="cats2"/><label for="cat0">Category1</label>
  <input type="checkbox" value="SlugB" id="cat1" class="cats2"/><label for="cat1">Category2</label>
  <input type="checkbox" value="SlugC" id="cat2" class="cats2"/><label for="cat2">Category3</label>
  <input type="checkbox" value="SlugD" id="cat3" class="cats2"/><label for="cat3">Category4</label>
  <input type="checkbox" value="SlugE" id="cat4" class="cats2"/><label for="cat4">Category5</label>
  <input type="hidden" id="cat2" name="category"/>
  <input type="submit" class="cat-search" value="search"/>
</form>
$(function(){
  $('body').on('click', '.cats2', function(){
    varcats=$('.cats2:checked') .map(function(){
      return this.value;
    }).get().join("+");
    $('#cat2') .val(cats);
  });
});

In the first place, I don't know if I can get the URL I want using the check box.

If the question mark is always included and it cannot be in the form of the URL you are looking for in the first place, I can give up, but if anyone knows, please take care of it.

wordpress

2022-09-30 13:50

1 Answers

I solved myself.
You can now use the search plug-in to display what you intended.
Thank you for editing.

The plug-in you used is a paid version of Search and Filter.


2022-09-30 13:50

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.