Seth
Seth

Reputation: 10454

Wordpress single-post-type template not displaying post

I have a theme with two custom post types, sermons, and members. I also have permalinks set to postname.

At first, single.php would catch general blog posts, as well as members, but not sermons... it would only display the index.php file.

After some research, I found resetting (saving) permalinks would reset them. This sort of worked by now catching the member custom posts, but only to display index.php for sermons.

this is how I call them...

// Custom Post types for Sermons
add_action('init', 'sermons');

function sermons() {
  $args = array(
    'labels' => array(
       'name' => __( 'Sermons' ),
       'singular_name' => __( 'Sermons' ),
       'add_new' => __( 'Add Sermon' ),
       'add_new_item' => __( 'Add Sermon' ),
       'edit_item' => __( 'Edit Sermon' ),
       'new_item' => __( 'Add Sermon' ),
       'view_item' => __( 'View Sermon' ),
       'search_items' => __( 'Search Sermons' ),
       'not_found' => __( 'No Home Sermons found' ),
       'not_found_in_trash' => __( 'No Sermons found in trash' )
   ),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    // 'menu_icon' => WP_CONTENT_URL . '/themes/####/images/home-widget.png',
    'rewrite' => true,
    'exclude_from_search' => true,
    'menu_position' => 20,
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
    'has_archive' => true
  );

  register_post_type('sermons',$args);
}

// Custom Post types for Members
add_action('init', 'members');

function members() {
  $args = array(
    'labels' => array(
       'name' => __( 'Members' ),
       'singular_name' => __( 'Members' ),
       'add_new' => __( 'Add Member' ),
       'add_new_item' => __( 'Add Member' ),
       'edit_item' => __( 'Edit Member' ),
       'new_item' => __( 'Add Member' ),
       'view_item' => __( 'View Member' ),
       'search_items' => __( 'Search Members' ),
       'not_found' => __( 'No Home Members found' ),
       'not_found_in_trash' => __( 'No Members found in trash' )
   ),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    // 'menu_icon' => WP_CONTENT_URL . '/themes/####/images/home-widget.png',
    'rewrite' => true,
    'exclude_from_search' => true,
    'menu_position' => 20,
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
    'has_archive' => true
  );

  register_post_type('members',$args);
}

I have tried single-sermons.php and single-members.php, neither seem to work. Is it the way I registered each custom post type that is breaking this?

**** EDIT **** Removed 'rewrite' => true from $args, and everything is fine, but I'd much rather have SEO friendly urls.

**** EDIT **** Fixed it... apparently, removing 'rewrite' => true in the args, refreshing the permalinks, and adding 'rewrite' => true again, did the trick.

Upvotes: 2

Views: 12544

Answers (4)

Azizul Haque
Azizul Haque

Reputation: 35

Setting publicly_queryable => true fixed my problem.

Upvotes: 0

fanta
fanta

Reputation: 561

Re-saving Permalinks worked for me. (Settings -> Permalinks -> SAVE).

Upvotes: 0

user2019515
user2019515

Reputation: 4503

You should do a flush_rewrite_rules() after you've created your custom post types, this will refresh the permalink structure for you.

Just add flush_rewrite_rules() after your register_post_type() function.

More info: http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

Upvotes: 11

Seth
Seth

Reputation: 10454

Fixed it... apparently, removing 'rewrite' => true in the args, refreshing the permalinks, and adding 'rewrite' => true again, does the trick.

Upvotes: 3

Related Questions