WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
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 '12 at 14:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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