WordPress.org

Forums

[resolved] Template hierarchy does not work correct. (2 posts)

  1. rreimche
    Member
    Posted 2 years ago #

    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, "http://mysite.com/requirements/my-post-title". 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 "http://mysite.com/requirements/".

    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?

  2. rreimche
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic