Wordpress loop showing duplicate categories
<p>I'm trying to create a loop that displays a list of the categories (as buttons) of a custom post type. I have a loop that works, but it is looping through all the custom posts and display each category. So right now if I have two posts with the same category, it will display that same category twice. Also I need to echo out custom classes for my isotope filter to work.</p>

<p>This is my code:</p>

<pre><code>            &lt;?php
            $args = array( 
                'post_type' =&gt; 'ondernemers', 
                'posts_per_page' =&gt; 10
                 );

            $loop = new WP_Query( $args );
            while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();

            $categories = get_the_category( $post-&gt;ID, 'taxonomy' );
            foreach( $categories as $category ) {
                echo '&lt;button class="button" data-filter=".'  . $category-&gt;slug . ' "&gt;&lt;div class="button-img-' . $category-&gt;slug . '"&gt;&lt;/div&gt;' . $category-&gt;name . '&lt;/button&gt;';
            }

            endwhile;
            ?&gt;
</code></pre>

<p>Is there a way to make the loop print each category only once, instead of once for each time it is just for each unique post?</p>