Wordpress single-post-type template not displaying post

10,818

Solution 1

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

Solution 2

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

Share:
10,818
Seth
Author by

Seth

Software Engineer at MojoTech. Find me tinkering at www.sethkrasnian.ski.

Updated on June 13, 2022

Comments

  • Seth
    Seth almost 2 years

    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.

  • Seth
    Seth almost 11 years
    It worked, by doing what it was supposed to. But it also reverted me to the original problem I had.
  • user2019515
    user2019515 almost 11 years
    I doubt the problem you were having is in the code above, I don't see anything unusual
  • Seth
    Seth over 9 years
    I mentioned in the question that saving the permalinks didn't completely solve the issue. mary louise parker codes??
  • fanta
    fanta over 9 years
    I know, but removing 'rewrite' => true didn't work for me, so the permalinks fix may work for somebody else with the same scenario. Cheers