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/?">
                        $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"/>

And here is where the choices are accessed:

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

Any suggestions? Thanks in advance!


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

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.