• Hello,

    Im trying to hide posts with specific tag from a category page, and to show those posts within that category when I need. Please look example below.

    Example:
    Hidden posts with tag AB from Category A > https://website.com/category/A (this I can do)
    Show posts with tag AB from Category A > https://website.com/category/A/?tdo_tag=AB (this I can’t do; if i hide with code below then those posts doesn’t show anymore)

    To filter posts I am using the plugin TDO Tag Fixed (its outdated but works fine)

    I have to do this for only 1 tag.

    This is the code i use:

    function exclude_tag_from_category( $query ) {
      if ($query->is_main_query() && $query->is_home() || $query->is_category()) {
             $query->set( 'tag__not_in', '22' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_tag_from_category' );

    Can I use else function or something?

    Any suggestion is highly appreciated.

  • The topic ‘How to hide a post with specific tag from category page’ is closed to new replies.