Query multiple taxonomies group slugs

2019-08-30 13:07发布

问题:

I have a checkbox function that I'm using for my search query. My problem is the url created when I search.

?ct_zipcode=&ct_event_type=birthday&ct_event_type=photovideo-shoot&Venue-search=true

When I have multiple taxonomy_names checked I only get the last slug in my search results.

I need my url to be rewritten like:

?ct_zipcode=&ct_event_type=birthday%2Cphotovideo-shoot&Venue-search=true 

Is there an easy way to change my url with rewrite? I've tried a little str_replace / preg_replace with no luck.

回答1:

Change the name of the input field to ct_event_type[] and you'll get the checked values as an array.


The HTML part should look like this:

<div>
    <label for="ct_<?php echo $name; ?>"> // for should be the same as checkbox id
        <input
          id="ct_<?php echo $name; ?>"
          name="ct_<?php echo $name; ?>"
          type="checkbox"
          style="margin-right:5px; margin-left:5px"
          value="<?php echo $t->slug; ?>" />   // <-- closing input
        <?php echo $t->name; ?>
    </label>
</div>

Note the use of label.