Title: Remove duplicate subcategory
Last modified: August 19, 2016

---

# Remove duplicate subcategory

 *  [diabeticdiet](https://wordpress.org/support/users/diabeticdiet/)
 * (@diabeticdiet)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/remove-duplicate-subcategory/)
 * I am trying this thing:
 *     ```
       <li>
       <a href="#subcategory-slug">Subcategory Name</a>
       </li>
       ```
   
 * and here is the code I am using:
 *     ```
       <li>
   
       				<?php $displayed = array();?>
       				<?php $my_query = new  WP_Query('category_name=Products&posts_per_page=9999');
       				while ($my_query->have_posts()) : $my_query->the_post();
       				?>
   
       				<a href="<?php foreach((get_the_category()) as $category ) { if($category->parent != 0) { echo '#'. $category->category_nicename . ' '; } } ?>">
       				<?php foreach((get_the_category()) as $category ) { if($category->parent != 0) { echo $category->cat_name . ' '; } } ?></a>
   
       			</li>
       ```
   
 * It kind of work only if there is just one post per subcategory, but if there 
   are more then one post for the same category I get duplicate content:
 *     ```
       <li>
       <a href="#subcategory-slug">Subcategory Name</a>
       </li>
       <li>
       <a href="#subcategory-slug">Subcategory Name</a>
       </li>
       <li>
       <a href="#subcategory-slug">Subcategory Name</a>
       </li>
       ```
   
 * So my question is how to alter the code so for multiple post to the same subcategory
   it displays just once that subcategory?

The topic ‘Remove duplicate subcategory’ is closed to new replies.

## Tags

 * [duplicate](https://wordpress.org/support/topic-tag/duplicate/)
 * [subcategory](https://wordpress.org/support/topic-tag/subcategory/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [diabeticdiet](https://wordpress.org/support/users/diabeticdiet/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/remove-duplicate-subcategory/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
