1

I can't figure out why my custom post type page template uses the archive page to display posts. I'm pretty sure I have the right files. These are the important files, regarding this issue, in my root folder:

Root

mytheme
- archive.php
- home.php
- single.php
- team.php
- single-team.php
- archive-team.php

Usage

 1. team.php is a custom page template. All team members are shown here.
 2. single-team.php displays a single team member.

My Post Type

 function create_post_type_team() { register_post_type( 'team',
   array(
       'labels' => array(
       'name' => __( 'Team' ),
       'singular_name' => __( 'Team' )
      ),
   'public' => true,
   'has_archive' => true,
   'supports' => array( 'title', 'editor', 'thumbnail' ),
   'taxonomies' => array('post_tag') 
    )
  );
}

add_action( 'init', 'create_post_type_team' );

My Problem

When I visit mysite/team (team.php), the page is using archive-team.php to display posts. It should use team.php which is assigned to the page as page template via the admin panel. The weird thing is that when I change the page url from /team to /team2, it does use team.php and not archive-team.php.

Notes

Before this problem occurred, mysite/team/member (single-team.php) was not working. I went to my permalink settings - did nothing - and went back. From this point mysite/team/member worked, but team.php started using archive-team.php. If I set has_arhive => false, it falls back to home.php.

Any help would be much appreciated!

1 Answer 1

1

You should add the code you have in team.php to archive-team.php. Also, read this.

By default, Wordpress matches the id of the custom post type to a file with the name archive-{custom_post_type_id}.php, and if it doesn't exist it uses the archive.php file.

3
  • Thank you for your reply. It does work, but now I have duplicated code in team.php and archive-team.php. I still need team.php to assigned the post type to a page. Is that good practice?
    – Tim
    Aug 17, 2014 at 11:15
  • Your function to register the custom post type is in the team.php file? A good practice would be to have that function in functions.php of your theme or to create a plugin and add it there (what I recommend). Anyway
    – Tomás Cot
    Aug 17, 2014 at 12:16
  • No no, my function is in functions.php. I'm trying to say that my team.php code and archive-team.php code are the exact same files now. That feels strange to me, but i'll leave that for what it is. Thanks.
    – Tim
    Aug 17, 2014 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.