Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.