In My wodpress Blog there are some categories use for the internal work. I want to hide that categories in blog homepage category list show under each post.

I print category list as print(the_category($postID));

How to hide or make filter for that category list print under each post?

1 Answer 1


I'm afraid that in this case you will have to go throught the categories and have some logic here. you can use a function like this one:

function filterCategories($postId,$excluded, $separator){
    $categoriesToDisplay = '';
    $count = 0;
    $allCategories = get_the_category($postId);
    foreach($allCategories as $category) {
        if ( !in_array($category->cat_ID, $excluded) ) {

           // get that category link
           $cat_link = $get_category_link($category->cat_ID);       
           $categoriesToDisplay .= $cat_link;

           // we want a separator, but not at the end...
           if($count < count($categories)){
               $categoriesToDisplay .= $separator;
        return $categoriesToDisplay;

It will trancate the categores you want without the excluded as links seperated by what ever you want (in this case "|") You can call it within your loop:

     <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
     <?php $id = get_the_ID(); ?>
     <?php echo filterCategories($id, array(1,2,3,4)," | "); ?>

$categories array will be the array of categories objects what you can then display as:

I haven't tested it, but it should work.

To get the excluded categories you can use a parent category called "excluded" or something like that. than they can be available for you easily:

$excluded = wp_list_categories("child_of=".$excludedCategoriId);

Hope it helps.

  • Thanks for the answer. This will print all the category list exclude hiding categories. Ho do I get categories only related to the post using this function? or how to pass post id to this?
    – Miuranga
    Jun 28, 2012 at 14:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.