WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display only some of the categories of a post - filter? (3 posts)

  1. maorb
    Member
    Posted 5 years ago #

    Hi,

    Suppose I have a post which is assigned to categories A, B and C.
    When viewing the post, one should regularly see the output of the_category() as something like: filed under categories A, B, C.

    I'd like to exclude one of the catregories to be viewed, although the post will still be assigned to that, meaning - the user will see something like - filed under categories: B, C.

    Category A is a fixed one, meaning I will want always to exclude A from being displayed on a post, so it might be even easier.

    How can I filter that? Will be happy for ideas.

    Thanks,
    Maor

  2. maorb
    Member
    Posted 5 years ago #


  3. maorb
    Member
    Posted 5 years ago #

    Found a solution. Change the word "out" to the name of the category to exclude from list.
    Enjoy the code

    <?php
    foreach((get_the_category()) as $category) {
    if ($category->cat_name != 'out') {
    echo 'term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.' ';
    }
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic