Conditional Queries within a Wordpress Loop
<p>I'm going to have a WP_Query run with arguments based on user input. The user can select multiple categories/terms and the query will filter based on the AND boolean.</p>

<pre><code>// main arguments
$args = array(
    'tax_query' =&gt; array(
        'relation' =&gt; 'AND',
        array(
            'taxonomy' =&gt; 'industry',
            'terms'    =&gt; $user_input,
        ),
        array(
            'taxonomy' =&gt; 'format',
            'terms'    =&gt; $user_input2,
        ),
    ),
);

// less specific arguments
$lessargs = array(
    'tax_query' =&gt; array(
        array(
            'taxonomy' =&gt; 'industry',
            'terms'    =&gt; $user_input,
        ),
    ),
);
</code></pre>

<p>If no results are returned in the first query, I want to run the second query with less specificity ($lessargs). I know I need to use if/else statements but I don't know the correct way to do this within the loop. Example:</p>

<pre><code>&lt;?php $the_query = new WP_Query( $args ); ?&gt;

&lt;?php if ($the_query-&gt;have_posts()) : ?&gt;

     &lt;?php while ($the_query-&gt;have_posts()) : the_post(); ?&gt;
        // Return Query Results
     &lt;?php endwhile; ?&gt;

  &lt;?php else : ?&gt;

    &lt;?php $the_second_query = new WP_Query( $less_args ); ?&gt;

    &lt;?php while ($the_second_query-&gt;have_posts()) : the_post(); ?&gt;
        // Return Second Query Results
    &lt;?php endwhile; ?&gt;

&lt;?php endif; ?&gt;
</code></pre>

<p>Is this the proper way to conditionally call queries if the previous query returns empty?</p>