Support » Themes and Templates » Template hierarchy does not work correct.

  • Resolved rreimche


    I have a custom post type named “requirement”. The rewrite for it is “requirements” ( ‘rewrite’ => array(‘slug’ => ‘requirements’) ):

    function requirement_register() {
    	$labels = array( /*here go my labels */ );
    	$args = array(
    				'labels' => $labels,
    				'public' => true,
    				'publicly_queryable' => true,
    				'show_ui' => true,
    				'query_var' => true,
    				/*'menu_icon' => get_stylesheet_directory_uri() . '/images/posttypeicon_pg.png',*/
    				'rewrite' => array('slug' => 'requirements'),
    				'capability_type' => 'post',
    				'hierarchical' => false,
    				'menu_position' => 5,
    				'supports' => array('title','editor','thumbnail')
    	register_post_type( 'requirement' , $args );

    I also have two templates for it:

    • single-requirement.php
    • archive-requirement.php

    I’ve created one post and went to it’s page within the front-end, that is, “”. It works OK, I see my post. But when I try to open the page that is supposed to show all the “requirements”, I get 404.php instead of archive-requirement.php. I open “”.

    And I can’t figure out why does that happen… And this is a real problem for me, because I can’t go on with the project without fixing it 🙁

    I’ve examined these two Codex pages:

    , and found out that it could be something about permalinks. The description of a problem is followed with an advice to change permalink structure to a different one from the actual and then change it back. I did so, but it didn’t help.

    Am I doing something wrong with the template structure, or is the problem around something different?

Viewing 1 replies (of 1 total)
  • I’ve figured it out. In oder for archive page of a custom type to exist the following should be added to $args of register_post_type() in my case:

    'has_archive' => 'requirements'

    See register_post_type() codex page for this parameter and what it can do.

Viewing 1 replies (of 1 total)
  • The topic ‘Template hierarchy does not work correct.’ is closed to new replies.