0

I've used a query that will query if the post in a specific category, to show a list of subcategories it belongs to.

The problem I'm having is I also want to exclude a specific subcategory from the output.

The current code is:

<?php
                    foreach((get_the_category()) as $childcat) {
                    if (cat_is_ancestor_of(81, $childcat)) {
                    echo '<li><a href="'.get_category_link($childcat->cat_ID).'">';
                     echo $childcat->cat_name . '</a></li> ';
                    }}
                ?>

Is there something I can add to this to exclude a category ID as well?

1
  • could this be done with an if statement? if ( $childcat->cat_ID !== 1234 ) where 1234 is the ID of the category to be excluded? I'm not seeing the need for any special WP functions
    – Tom J Nowell
    May 4 at 12:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.