Dynamically tax_query terms
<p>To display all the categories name with checkbox from custom taxonomy called <code>ct_category</code> I have the following code: </p>

<pre><code>$terms = get_terms('ct_category');
foreach ( $terms as $term ) {
echo '&lt;li class='.$term-&gt;term_id.'&gt;&lt;label &gt; &lt;input class="taxonomy_category" type="checkbox" name="taxonomy_category['.$term-&gt;term_id.']" value ="'.$term-&gt;term_id.'" /&gt;'.$term-&gt;name.'&lt;/label &gt;&lt;/li&gt;';          
}                                             
</code></pre>

<p>I would like to display content only from checked categories. I tried following that didn't work:</p>

<pre><code>$args = array(
'post_type' =&gt; 'cpt',
'tax_query' =&gt; array(
            array(
               'taxonomy' =&gt; $ct_category,
               'field' =&gt; 'term_id',
               'terms' =&gt; $_POST['taxonomy_category']
                )
              )
           ); 
$loop = new WP_Query( $args );
</code></pre>

<p>I can guess that the issue is in <code>'terms' =&gt; $_POST['taxonomy_category']</code>. If name attribute <code>taxonomy_category['.$term-&gt;term_id.']</code> can be displayed as array in <code>'terms' =&gt;</code>, the issue would be fixed. Spent plenty of times searching google but couldn't find any solution. </p>

<p>Here is the full code</p>

<pre><code>&lt;?php

function add_meta_box() {
    add_meta_box( 'ct_metabox', 'CT', 'meta_box_content_output', 'cpt', 'normal' );
}
add_action( 'add_meta_boxes', 'add_meta_box' ); 


function meta_box_content_output ( $post ) {

    wp_nonce_field( 'save_meta_box_data', 'meta_box_nonce' );

    $taxonomy_category =  get_post_meta( $post-&gt;ID, 'taxonomy_category', true );

    function categories_checkbox(){
        $terms = get_terms('ct_category');

        foreach ( $terms as $term ) {
        echo '&lt;li class='.$term-&gt;term_id.'&gt;&lt;label &gt; &lt;input class="taxonomy_category" type="checkbox" name="taxonomy_category['.$term-&gt;term_id.']" value ="'.$term-&gt;term_id.'" /&gt;'.$term-&gt;name.'&lt;/label &gt;&lt;/li&gt;';          
        }
    }
&lt;?

&lt;ul&gt;
    &lt;li&gt;
        &lt;?php categories_checkbox() ?&gt;
    &lt;li&gt;
&lt;/ul&gt;         

&lt;?php
}

function save_meta_box_data( $post_id ) {

    // Check if our nonce is set.
    if ( ! isset( $_POST['meta_box_nonce'] ) ) {
        return;
    }

    // Verify that the nonce is valid.
    if ( ! wp_verify_nonce( $_POST['meta_box_nonce'], 'save_meta_box_data' ) ) {
        return;
    }

    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if ( defined( 'DOING_AUTOSAVE' ) &amp;&amp; DOING_AUTOSAVE ) {
        return;
    }

    // Check the user's permissions.
    if ( isset( $_POST['post_type'] ) &amp;&amp; 'page' == $_POST['post_type'] ) {

        if ( ! current_user_can( 'edit_page', $post_id ) ) {
            return;
        }

    } else {

        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return;
        }
    }



    $taxonomy_category_value = "";

   if(isset($_POST["logo_taxonomy_category"])) {
        $taxonomy_category_value = sanitize_text_field( $_POST["logo_taxonomy_category"] );
    }   
    update_post_meta($post_id, "logo_taxonomy_category", $taxonomy_category_value);

}
add_action( 'save_post', 'save_meta_box_data' );
?&gt;

&lt;?php
$args = array(
  'post_type' =&gt; 'cpt',
  'tax_query' =&gt; array(
        array(
           'taxonomy' =&gt; $ct_category,
           'field' =&gt; 'term_id',
           'terms' =&gt; $taxonomy_category
            )
          )
       ); 
$loop = new WP_Query( $args );
?&gt;
</code></pre>