user966834
user966834

Reputation: 85

Remove specific category from list in wordpress

im using

<?php
    foreach((get_the_category()) as $category) {
        $cats .= $category->cat_name . ', ';
    }
    echo rtrim($cats, ', ');
?>

to display the category names of a post. How would i go about out removing a specific category from this list

Upvotes: 0

Views: 343

Answers (1)

Howli
Howli

Reputation: 12469

Untested but something like this should work:

<?php
foreach((get_the_category()) as $category) 
{
    if($category->cat_name == "category name")
    {

    }
    else
    {
        $cats .= $category->cat_name . ', ';
    }
}
echo rtrim($cats, ', ');
?>

Upvotes: 3

Related Questions