2

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.

2
  • 1
    Just wondering if setting 'publicly_queryable' => true, as an argument helps. codex.wordpress.org/Function_Reference/… . How about if you set up single-sermons.php and single-members.php templates?
    – McNab
    May 6, 2013 at 18:50
  • yes, tried that. It wouldn't render for some reason. I will try your suggestion though. Thanks alot
    – Seth
    May 6, 2013 at 18:59

4 Answers 4

11

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

2
  • It worked, by doing what it was supposed to. But it also reverted me to the original problem I had.
    – Seth
    May 7, 2013 at 13:38
  • I doubt the problem you were having is in the code above, I don't see anything unusual May 8, 2013 at 16:26
3

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

0

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

2
  • I mentioned in the question that saving the permalinks didn't completely solve the issue. mary louise parker codes??
    – Seth
    Nov 28, 2014 at 0:58
  • 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
    – fanta
    Dec 8, 2014 at 5:24
0

Setting publicly_queryable => true fixed my problem.

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.