Title: Exclude category from loop
Last modified: February 22, 2022

---

# Exclude category from loop

 *  Resolved [comehere](https://wordpress.org/support/users/comehere/)
 * (@comehere)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/exclude-category-from-loop-3/)
 * Hello ScriptsTown,
 * I come with another question if you can help,
 * Is it possible to exclude children categories of a parent category from the loop
   by ID or something?
 * Long story short, I want to display children categories from a parent category
   with ID “5” with images in separate loop bellow, got this part done.
 * I have installed a plugin that displays category images, I got the code working
   somehow, place it right before <!– .cat-links –> into the “content-single” php
   file and created another loop to display them, now the children categories of“
   5” are show with images.
 * My problem is the children categories of “5” are show twice, would it be possible
   to exclude them from the first loop?
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Theme Author [ScriptsTown](https://wordpress.org/support/users/scriptstown/)
 * (@scriptstown)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/exclude-category-from-loop-3/#post-15393377)
 * Hi,
 * You can recreate the first loop using “wp_get_post_categories” and its options.
   In this case, it’s “exclude_tree”.
 * Here’s the [new code](https://github.com/scriptstown/custom-child-themes/blob/main/23-02-2022/exclude-categories/content-single.php)
   for content-single.php where category ID “5” and its children are excluded from
   the loop.
 * You can check more options that you can use in “wp_get_post_categories”:
    [https://developer.wordpress.org/reference/classes/wp_term_query/__construct/](https://developer.wordpress.org/reference/classes/wp_term_query/__construct/)
 * Thanks!
 *  Thread Starter [comehere](https://wordpress.org/support/users/comehere/)
 * (@comehere)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/exclude-category-from-loop-3/#post-15395392)
 * It fixed the issue,
 * I tried before my own written code loops on local but failed to recreate this,
   will play with the example you provided more.
 * Thanks for the help

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Exclude category from loop’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/pressbook/2.1.9/screenshot.png)
 * PressBook
 * [Support Threads](https://wordpress.org/support/theme/pressbook/)
 * [Active Topics](https://wordpress.org/support/theme/pressbook/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/pressbook/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/pressbook/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 2 replies
 * 2 participants
 * Last reply from: [comehere](https://wordpress.org/support/users/comehere/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/exclude-category-from-loop-3/#post-15395392)
 * Status: resolved