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

Is there any way to filter the categories of a post? I am using wp_get_post_categories( $post -> ID ); i want to filter this listing i.e. if(post_name or post_id == "some id or some name") {it should not be displayed}

share|improve this question
up vote 0 down vote accepted

have you tried something like,

$post_categories = wp_get_post_categories( $post -> ID  );

foreach($post_categories as $c){
    $cat = get_category( $c );
    if ( $cat->slug != "cat" ) {
       echo "$cat->name";
share|improve this answer

You can do this by using in_category():

$post_categories = wp_get_post_categories( $post->ID );

foreach( $post_categories as $cat_id ) {
    if ( in_category( $cat_id, POST_ID ) ) {
        // it should not be displayed
    } else {
        // it should be displayed

Where POST_ID should be the ID of the post wich you want to check.

share|improve this answer

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.