0

I have multiple custom post types set up. I've been through this process many times, on many sites and have never once had a problem with it.

The post type is registered as 'glossary'. The archive is 'archive-glossary.php'. The single is 'single-glossary.php'.

On my archive page, I basically have the following:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>

etc...

If you click one of those links that would normally take you to a single-glossary.php it just reloads archive-glossary.php.

I have many post types set up the exact same way, on the same site. I'm just beginning to work out a page template, so they're all very generic. I've flushed the permalinks, deleted and re-registered the post type, changed the theme, checked and double-checked for typos, cleared my browser cache totally, used 4 different browsers, and just can't see anything that would be causing this.

I'm hoping someone can offer some sage troubleshooting advice.

Upon request, the following is what I use to create custom post types:

class CustomPostType{
    protected $textdomain;
    protected $posts;

    public function __construct($textdomain){
        $this->textdomain = $textdomain;
        $this->posts = array();
        add_action('init', array(&$this, 'register_custom_post'));
    }

    public function make($type, $properLabel, $singularLabel, $pluralLabel, $icon, $slug, $settings = array()){
        if(isset($singularLabel)){$singluarLabel = $singularLabel;}else{$singularLabel = '';}
        if(isset($pluralLabel)){$pluralLabel = $pluralLabel;}else{$pluralLabel = '';}
        $default_settings = array(
            'labels' => array(
                //Title Of the Group
                'name' => __($properLabel, $this->textdomain),
                //Individual Type
                'singular_name' => __($singluarLabel, $this->textdomain),
                // "All %Items%" Menu Item
                'all_items' => __( 'All '.$pluralLabel, $this->textdomain), 
                //The "Add New" Menu Item
                'add_new' => __( 'Add New '.$singularLabel, $this->textdomain ),
                //Add New Display Title 
                'add_new_item' => __('Add New '.$singularLabel, $this->textdomain), 
                //Edit Dialog
                'edit' => __( 'Edit', $this->textdomain), /* Edit Dialog */
                //Edit Display Title
                'edit_item' => __('Edit '.$pluralLabel, $this->textdomain),
                //New Display Title
                'new_item' => __('New '.$singularLabel, $this->textdomain),
                //View Display Title
                'view_item' => __('View '.$singularLabel, $this->textdomain),
                //Search Custom Type Title
                'search_items' => __('Search '.$pluralLabel, $this->textdomain),
                //Displays if No Entry Found
                'not_found' => __('No '.$pluralLabel.' found.', $this->textdomain),
                //Not found in Trash
                'not_found_in_trash' => __('No '.$pluralLabel.' found in trash.', $this->textdomain),
                //Only in Hierarchical Post Types "Parent %Item%"
                'parent_item_colon' => __('Parent '.$singluarLabel, $this->textdomain),
                ),
            //Custom Type Description
            'description' => __( 'This is the '.$properLabel.' custom post type', $this->textdomain), /* Custom Type Description */
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => 20,
            'menu_icon' => get_stylesheet_directory_uri() . '/library/images/admin-panel/'.$icon.'-icon.png',
            'rewrite' => array(
                'slug' => $slug
                ),
            'has_archive' => sanitize_title_with_dashes($slug),
            'capability_type' => 'post',
            'hierarchical' => true,
            'supports' => array(
                'title',
                'editor',
                'author',
                'thumbnail',
                'excerpt',
                'custom-fields',
                'revisions',
                'sticky',
                'page-attributes'
                ),
            );
        $this->posts[$type] = array_merge($default_settings, $settings);
    }

    public function register_custom_post(){
        foreach($this->posts as $key=>$value) {
            register_post_type($key, $value);
        }
    }
}//End Class

$type_glossary = new CustomPostType('thetextdomain');
$type_glossary->make('glossary', 'Glossary', 'Term', 'Terms', 'glossary', 'glossary');
  • Post you code that you use to register your post type – Pieter Goosen Sep 16 '14 at 4:53
  • Edited to add code used to register post type. – Rob Sep 16 '14 at 4:59
0

try registering with a different name; doesn't always make sense, but it's a proper check.

if that doesn't resolve – which would be strange since the other CPTs work – check any functions/plugins hooking into template_redirect. might even need to do a backtrace to see the file load progression. not sure if it does this specifically, but Query Monitor is a fantastic plugin for devving and solving issues.

  • Thank you. It was a redirect left over from the last theme I did, and I completely forgot that it was buried there. Thank you doubly for mentioning Query Monitor, which I have somehow never come across but offers an amazing wealth of information! – Rob Sep 16 '14 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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