WordPress.org

Ready to get started?Download WordPress

Forums

How can exclude some tags from 'the_tags' list? (5 posts)

  1. snoogly
    Member
    Posted 6 years ago #

    I want to use 'the_tags' to generate a list of a post's tags, but I need to exclude certain tags from the list.

    How do I do this? I have hunted in the Codex, but can't find a way to exclude tags.

  2. quirksmode
    Member
    Posted 6 years ago #

    I am having the same problem, did you ever solve this?

  3. JesseHeap
    Member
    Posted 6 years ago #

    I think this is what you are looking for:

    Excluding Tags from Posts in WordPress

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Or you could add a filter and filter them out entirely...

    function exclude_tags($tags) {
    foreach ($tags as $tag)
    switch ($tag->name) {
     case 'exclude-this-tag':
     case 'exclude-this-tag-too':
      break;
     default:
      $newtags[] = $tag;
    }
    return $newtags;
    }
    add_filter( 'get_the_tags', 'exclude_tags');
  5. Dunkkan
    Member
    Posted 5 years ago #

    You guys you'r da mastas'

    Could I modify the Otto's code (Otto, if reading, how do I modify your code) to exclude, not a compact tag, but an expresion foundable in a tag ?

    Let's say I have a tag : Lions in The Circus.

    And : Birds in The Circus.

    And I need to exclude every tag where the 'Circus' expression is present.

    I know the first solution allows that, but it serves to print a conventional list of tags, when my intention is use the filtered query for another purpose (a customized related posts plugin).

    With a generic function I could get it.
    It must be out there some magical bit of code, some !empty function, or switch, or any of this magical php words which can work it out.

    So please, let's awake this threat :)

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic