while循环跳过具有相同元值的条目

I have a list of entries and some of them have the same code. For the overview of the entries I need only one of them. I created a while loop with a counter and code value checker which returns the IDs of the entries in an array if there are more entries with the same code ID, and false if there is none, and its works. However, I think there is maybe a better way to do this.

        <?php

        $c                   = 0;

        if ( $r->have_posts() ):
            while ( $r->have_posts() ):
                $r->the_post();


                $course_code_id = rp_get_meta( "rp_course_code" );
                if ( rp_meta_value_exists( 'rp_course_code', $course_code_id, $post_type, 'published' ) ) {
                    if ( $c > 1 ) {
                        $c = 0;
                    }
                } else {
                    $c = 0;
                }

                $c ++;

                if ( $c > 1 ) {
                    continue;
                }

                echo rp_get_view( 'courses', 'loop/' . $style, true);

            endwhile;
            wp_reset_postdata();

        endif;
        ?>