Support » Fixing WordPress » Custom Post Type Archive Page Issues

  • Resolved fredhead


    I’ve got everything working with three custom content types except the archive list pages and category list pages. I don’t want to use plugins (tried them, too much complexity, not enough control, insufficient results, conflicts with other plugins). If people can point me to solutions and ideas, I’d be grateful.

    Using one content type as an example, here is my register function:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I’ve created an FAQ template and assigned it to a page called FAQs (so the URL is /faqs, as in the rewrite value above, in the register function):

    [Code moderated as per the Forum Rules. Please use the pastebin]

    First problem: when I call up I get an initial page load of 2 items with an “Older Posts” link. When I click the Older Posts link, however, I get a 404 for /faqs/page/2/ URL.

    Second problem: on the page, when I click a category link included in an entry, I get the default Hello World post, not my custom type FAQs entries. I’m using the default WordPress category taxonomy, not custom taxonomies (not needed, in this case).

    When I created an archive-faq.php page, I still got the 404. So I switched to the older method of using and assigning a template.

    Any ideas how to get the /page/2/ URL working with my template, or how to get archive-faq.php to be recognized by WordPress, would be appreciated. Same for getting the categories to display (which are not custom taxonomies).

    Thank you!

Viewing 15 replies - 1 through 15 (of 18 total)
  • Moderator keesiemeijer


    Put your code in the pastebin and submit it and post the link to it here.
    some further reading:

    Exactly what code do you need to see? My functions.php is nearly a 1,000 lines long and much of it spurious to this situation. Are there specific custom post type functions you need to see? That’s why I posted the register function (so you can see the rewrite value) and the template.

    I’ll read the pagination posts you reference. Thank you for that.

    I had this problem I got round it two ways. I created a CPT archive page which is the format of archive-CPT name

    change CPT to your post type and then set the loop query to post_type=CPT name.

    So for portfolio you’d have


    and your query as:

    query_posts( ‘post_type=portfolio’)

    Also make sure you refresh your permalinks, just saving is enough. As you need to ensure WP is aware of the CPTs.

    Sorry, keesie, see now that my code was whacked in my original post. Here’s the Pastebin URL:

    @csd_images, I think that I’ve tried your approach but will try again. Not finding anything clicking down keesie’s tag list, so far.


    Part of the mystery solved by reverting permalinks to expose the query string values. The “Older Stories” link goes to a page_id value that is for the page instead of a content type. So the querystring values are:


    Any ideas the reason the content type is not passed?

    I have an archive template with the filename including the content type name, with the generic WP calls to header, sidebar, and footer, as well as basic content. No wp_query.

    Question: If I call my new content type URL, I should see the basic content, correct? That’s how I would test the right template is being called?

    My problem is that doing this generates a 404 page. I want to understand how WP got to that 404 page. By first not obsessing about the wp_query code but instead trying to figure out how to get WP to call the correct template.

    Any ideas how to determine the path WP takes to get to the 404 page?

    The pastebin code is still valid, above. The register_post_type name is ‘faq’, the URL is /faq, and the archive file is archive-faq.php. None of that appears to work: I get a 404 page all the time.

    Appreciate any help debugging this problem.

    Update: With permalinks “off” to show the querystring, I set the URL to ?post_type=faq then added “xyz” to my archive-faq.php, archive.php, and index.php files, one by one, to match the template hierarchy WP follows. For some reason, my WP install ignores archive-faq.php and archive.php and only uses the index.php template. That’s the mystery I’m trying to solve, for now: how to get WP to use the archive-faq.php template.

    Moderator keesiemeijer


    try resaving your permalink structure under Settings > Permalinks

    If you also have a Page called “faq” this could also cause troubles.

    @keesie I’ve reset permalinks all the time, every test. I also don’t have an FAQ page (I should be so lucky!).

    Moderator keesiemeijer


    is your archive template called: archive-faq.php? I will try your code on my testserver

    Yes. The -typename.php is the archive file.

    The problem appears to be changing the slug from the value used to register the content type. Specifically, if I set the rewrite value in $args to ‘faqs’ while the content type is registered as ‘faq’ these problems happen. If I set rewrite to true, WP happily displays the index.php template (still ignoring the archive-faq.php and archive.php templates).

    Ideally I want to have the slug and content type name different so that my content types will be custom to the install, not likely to be stepped on by some future WP upgrade or plugin that offers a content type called ‘faq’ or ‘faqs’.

    My goal is to come up with an instance of creating a content type that works to add/edit/delete content, display an archive page, and display a detail/single page. Displaying the archive page eludes me.

    Appreciate your help.

    Moderator keesiemeijer


    If I register with this it works:

    function faqs_register() {
    	$labels = array(
    		'name' => _x('FAQs', 'post type general name'),
    		'singular_name' => _x('FAQ Item', 'post type singular name'),
    		'add_new' => _x('Add New', 'FAQ item'),
    		'add_new_item' => __('Add New FAQ'),
    		'edit_item' => __('Edit FAQ'),
    		'new_item' => __('New FAQ'),
    		'view_item' => __('View FAQ'),
    		'search_items' => __('Search FAQ'),
    		'not_found' =>  __('Nothing found'),
    		'not_found_in_trash' => __('Nothing found in Trash'),
    		'parent_item_colon' => ''
    	$args = array(
    		'labels' => $labels,
    	            		'public' => true,
    	            		'publicly_queryable' => true,
    	            		'show_ui' => true,
    	            		'show_in_menu' => true,
    	            		'_builtin' => false,
    	            		'query_var' => true,
    	            		'rewrite' => array('slug' => 'faqs', 'with_front' => false),
    	            		'menu_icon' => get_stylesheet_directory_uri() . '/icons/faqs.png',
    	            		'capability_type' => 'post',
    	            		'has_archive' => true,
    	            		'hierarchical' => false,
    	            		'menu_position' => 4,
    	            		'supports' => array('title','editor','thumbnail'),
    register_post_type( 'faq' , $args );

    Interesting. It works with permalinks on but not with the default permalinks. Even better, the URL /faqs now calls the archive-faq.php template. So thank you!

    For the record, the rewrite value was the only thing you changed in $args?

    Moderator keesiemeijer


    What doesn’t work? the pagination?

    For the record, the rewrite value was the only thing you changed in $args?

    I just took the $args of an old custom post type I had and replaced your $args with it.
    also: 'has_archive' => true,

    … and I notice _builtin is added to $args.

    What doesn’t work is the underlying problem of pulling the correct template. Default permalinks uses index.php in all cases if I use the content type name registered in functions.php. When I switch to a defined permalink, the /faqs URL pulls from archive-faq.php.

    Now that /faqs pulls from the right template, I can add content and see if the /page/2/ pagination works.

    Let you know how it goes.

    Moderator keesiemeijer


    are you using an url like this “” when viewing the faq archive with default permalinks

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Custom Post Type Archive Page Issues’ is closed to new replies.