Permalink/Custom Post Type issue — unable to solve

One of the custom post types I have on a site now no longer works: the database entries still exist but I cannot access the posts. I think this is the known permalinks issue, but having been through a great many posts and having tried the solutions offered, I’m still stuck with the problem.

I have a ‘single,php’ file with some sorting code which then redirects to three different single files (‘single-author.php’, ‘single-book.php’, ‘single-event.php’).

Read More

Things I’ve tried:

  • Switching permalink structure and switching back
  • Flushing rewrite rules
  • Checking rewrite rules in .htaccess

If I create a new entry in this custom post type I can see it in ‘preview’ but as soon as I publish it I get a 404. The problem does not seem to be affecting the other custom post types I have running on the site. Other than the recent WP update, I’ve not made any changes to the site.

I attach the relevant code below — any pointers or help would be greatly appreciated as I’m not sure what else to try in order to fix the problem.

Many thanks!

add_action('init', 'authors_register');

function authors_register() {

$labels = array(
    'name' => _x('Authors', 'post type general name'),
    'singular_name' => _x('Author', 'post type singular name'),
    'add_new' => _x('Add New', 'portfolio item'),
    'add_new_item' => __('Add New Author'),
    'edit_item' => __('Edit Author'),
    'new_item' => __('New Author'),
    'view_item' => __('View Author'),
    'search_items' => __('Search Authors'),
    '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,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => 5,
    'supports' => array('title','thumbnail','revisions','excerpt'),
    'taxonomies' => array('category', 'post_tag')
  ); 

register_post_type( 'author' , $args ); 

}

Sorting/switching code in single.php:

<?php if ('post_type=book') { include (TEMPLATEPATH . '/single-book.php'); } 

elseif ('post_type=event') { include (TEMPLATEPATH . '/single-event.php'); } 

elseif ('post_type=author') { include (TEMPLATEPATH . '/single-author.php'); } 

else { include (TEMPLATEPATH . '/single-post.php'); } ?>

Related posts

Leave a Reply

1 comment

  1. <?php if ('post_type=book') { include (TEMPLATEPATH . '/single-book.php'); } 
    
    elseif ('post_type=event') { include (TEMPLATEPATH . '/single-event.php'); } 
    
    elseif ('post_type=author') { include (TEMPLATEPATH . '/single-author.php'); } 
    
    else { include (TEMPLATEPATH . '/single-post.php'); } ?>
    

    Will always return single-book.php

    ‘post_type=books’ will always return true. You must have the post_type in a variable and check for each

    <?php 
    $post_type =  get_post_type();
    
    if ( $post_type == 'book') { include (TEMPLATEPATH . '/single-book.php'); } 
    elseif ($post_type == 'event') { include (TEMPLATEPATH . '/single-event.php'); } 
    elseif ($post_type == 'author') { include (TEMPLATEPATH . '/single-author.php'); } 
    else { include (TEMPLATEPATH . '/single-post.php'); } ?>
    

    Also, author is not a reserved post type. The reserved post types are:

    post
    page
    attachment
    revision
    nav_menu_item