How to get all unique categories for posts in loop?
EDIT: Moved $i = 0 outside the loop. That should get you the full list of categories. $get_posts = new WP_Query(); $i = 0; $get_posts->query($args); if($get_posts->have_posts()) { $cats = array(); while($get_posts->have_posts()) { $get_posts->the_post(); $post_categories = wp_get_post_categories( get_the_ID() ); foreach($post_categories as $c){ $cat = get_category( $c ); $cats[$i] = $cat->slug ; $i++; } } //endwhile $result … Read more