0

I'm creating a form that loops through all the terms of a taxonomy. Multiple terms can be selected and they get passed in the url. I'm trying to get all the terms on another page but I'm only able to get the last one. I'm not sure if this is the best way to do this but if anyone can give me a tip as to what I'm doing wrong.

First, here is the form

                        <form method="get" id="searchProperties" action="<?php echo home_url()?>/filter-2/?">
                            <?php
                        $termsCounty = get_terms( 'County', array(
                              'hide_empty' => 0
                              ) );
                        echo '<ul>';
                            foreach ($termsCounty as $term) {
                                $termCounty = $term->name . 'PropertyFilter';
                                echo '<li><label><input type="checkbox" name="t"  value="il_' . $term->name . '">' .$term->name. '</label></li>';
                            }
                        echo '</ul>';

                        ?><input type="submit" value="FILTER"/>
                        </form>

And here is where the choices are accessed:

echo $term = $_GET['t'];

Any suggestions? Thanks in advance!

1 Answer 1

0

Use brackets in the name attribute:

'<input type="checkbox" name="t[' . $term->name . ']"  value="1">

Then get the keys with:

array_keys( $_GET['t'] );

See also: Settings API with arrays example

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.