Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this structure:

taxonomy
    - term1
    -- child term1
    -- child term2

    -term2
    -- child term1
    -- child term2

I have two select boxes. First one shows the parent terms (term1 and term2) and the second one shows the childs of the selected parent.

I submit the form to "search-results.php". How can I get the values of both selects to create this kind of query?

$args = array(
   'tax_query' => array(                        
       array(
          'taxonomy' => 'state',
          'field' => 'slug',
          'terms' => array( term1, childTerm2 ),
          'operator' => 'IN'
       )
    )
);

Thanks.

share|improve this question
add comment

1 Answer

It all depends on how you're trying to do it. When it comes to filtering results, i usually setup the form to use $_GET and filter the results when the page loads again:

if (isset($_GET['term'])) {
    $term = $_GET['term'];
} else {
    $term = 'defaultTerm';
}

if (isset($_GET['childterm'])) {
    $childterm = $_GET['childterm'];
} else {
    $childterm = 'defaultChild';
}

$args = array(
   'tax_query' => array(                        
       array(
          'taxonomy' => 'state',
          'field' => 'slug',
          'terms' => array( $term, $childterm ),
          'operator' => 'IN'
       )
    )
);
share|improve this answer
    
Thanks for your answer, but... if $childterm is null because de user has not selected nothing in the second select box? –  rec Jun 10 '12 at 21:25
    
you can use $childterm = '' instead of 'defaultChild' for that, so that the query will bypass the empty positions on the array. –  moraleida Jun 10 '12 at 21:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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