title: How can I make this Php WP_Query returning categories only once?
body: <p>This loop returns the categories of each post, showing it multiple times. Instead, I want to show categories once, this is a filter by category functionality.</p>
  
  <pre><code>&lt;div id="filter-box" class="filter-box"&gt;
  
          &lt;?php 
              $args = array (
                  'post_type'     =&gt; "post",
                  'post_status'   =&gt; "publish",
                  'order'     =&gt; 'ASC',
                  'orderby'   =&gt; 'title' ,
                  'posts_per_page'    =&gt; -1);
  
          $all_query = new WP_Query($args);
  
              if ($all_query-&gt;have_posts()): 
                 while ($all_query-&gt;have_posts()): 
                    $all_query-&gt;the_post(); 
            ?&gt;
              &lt;a href="#" class="filter-btn" data-cat="&lt;?php get_cat($post-&gt;ID); ?&gt;"&gt;&lt;?php get_cat($post-&gt;ID); ?&gt;&lt;/a&gt; 
              &lt;?php  
                   endwhile;  
                         endif;
                           wp_reset_postdata();
          ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the function from functions.php</p>
  
  <pre><code> function get_cat($post_id) {
      $category_detail=get_the_category($post_id);
      foreach($category_detail as $cd) {
        echo $cd-&gt;cat_name;
      }
    }
  </code></pre>
  
  <p>Want to display the categories only once as they appear once for each of the posts.</p>