WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?
    $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(
$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
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
great edit, @kaiser – gmazzap Jul 30 '13 at 20:47

Your Answer


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.