title: How to fetch all custom terms of posts having particular meta value in WordPress?
body: <p>I an having around 6000 posts with different meta value to a particulate key 'CC101_type'.
  Now I want to fetch all terms of those posts having specific meta value.</p>
  
  <pre><code>    $args = array(
          'post_type'         =&gt; 'coupon',
          'posts_per_page'    =&gt; -1,
          'meta_query'        =&gt; array(
                  'relation' =&gt; 'AND',
              array(
                  'key'       =&gt; 'CC101_deactive',
                  'value'     =&gt; "off",
              ),
              array(
                  'Key'       =&gt; 'CC101_type',
                  'value'     =&gt; 'Deals'
              )
          )
      );
  
  
      $query      = new WP_Query($args);
      $all_categories = array();
          foreach($query-&gt;posts as $post=&gt;$p){
              $id = $p-&gt;ID;
              $terms = wp_get_post_terms( $id, 'coupon_category', array("fields" =&gt; "all") );
              foreach($terms as $k =&gt; $cat){
          $all_categories[$cat-&gt;term_id] = $cat-&gt;name;
          }
      }
  </code></pre>
  
  <p>I tried to do the above task by getting all posts first based on meta value and then get there terms.
  But it returned nothing when I get all posts <code>'posts_per_page'  =&gt; -1,</code> on the other side when I limit it to 20 posts it starts working.</p>
  
  <p>Is there any other way to do it ?</p>