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.

E.g. I have something like that:

$continent = $_POST['continent'];

if ($continent != 0) {
    // get specific taxonomy e.g. with id=3 which is africa
    $continent_query =  array(
                    'taxonomy' => 'continent',
                    'field' => 'term_id',
                    'terms' => $continent 
                );
} else {
    // how to build query array to search all terms?
    // I DON"T KNOW THIS CODE!!!
    $continent_query =  array( ?????????????? );
}

I am sending continent variable via post form and it's an integer. If it's "0" (all contintent in select box) then I need to build the $continent_query to query all terms. If it's specific then query e.g. only 2 or 3 etc.

This is the query:

$args = array(
        'post_type' => array( 'post' ),
        'posts_per_page' => 10,
        'tax_query' =>  array(
                            $continent_query,
                        )
        );
$wp_query = new WP_Query( $args );

Any idea how to do that for "0"?

share|improve this question
    
Just a question: Is $content actually 0 as in integer zero? Or is it false? Just curious what type it is (bool/int). –  kaiser Jul 30 '13 at 22:50
    
It's integer from a selectbox like: <option value="0">All Continents</option> –  Derfder Jul 31 '13 at 4:48
add comment

1 Answer 1

up vote 1 down vote accepted
$continent_query =  array(
   'taxonomy' => 'continent',
   'field' => 'term_id',
   'terms' => 0 != $continent ? $continent : get_terms('continent', array('fields'=>'ids'))
);
share|improve this answer
    
great, thanks a lot ;) –  Derfder Jul 30 '13 at 20:42
1  
great edit, @kaiser –  G. M. Jul 30 '13 at 20:47
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.