Support » Themes and Templates » tag.php acting weird with custom post types

  • Resolved nadine00



    I have a tag.php template, and currently it does not work when you click a tag with an article that is associated with a custom post type. I’m really confused, because its a site-wide tag….there’s no upfront reason it shouldn’t work.

    But the tag.php template just displays no article.

    The funny thing is that this: <?php single_tag_title( ); ?> …works fine.

    Do I have to “get the current tag” and pass that into a custom query or something? Do I have to use an archive template instead? Am I just missing something really obvious that I can’t find in the codex?

    I’m really new to custom post templates and so far, easy to set up: confusing to retrieve stuff from.

    So…help please? 🙁


Viewing 4 replies - 1 through 4 (of 4 total)
  • Anyone?


    Basically what’s going on is this:

    I go to Articles. Articles is a custom post type. In this custom post type I have allowed the user to use all the existing tags on the site.

    I click on a tag in a post that is posted in “Articles” it uses the tag.php template, but won’t show posts with that tag. It will however show the tag title. So I don’t really know what’s going on.

    Wrong template to be using maybe?

    So apparently, this is a bug:

    And this, which I found over at stackexchange is a good fix.

    <?php function post_type_tags_fix($request) {
        if ( isset($request['tag']) && !isset($request['post_type']) )
        $request['post_type'] = 'any';
        return $request;
    add_filter('request', 'post_type_tags_fix');?>

    WP’s support for custom post-types is as varied and disorganized as its code. I noticed that posts show up in category and tag lists if you set the “has_archive” argument to true when you register your custom post-types via WP’s register_post_type() function:

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘tag.php acting weird with custom post types’ is closed to new replies.