0

Trying to get a post to show up at http://beernews.org/supporter/rare-beer-club/ but am getting 404 instead. An example of what the page should look like is: http://beernews.org/brewery/5-rabbit-brewery/. When I do a search, it shows up as an excerpt in the results. Just can't get the template single-supporter.php to trigger for some reason. I have set up the post type (And corresponding taxonomy) exactly like every other post type and taxonomy.

I have flushed the cache and CDN.

I don't have a live server testing environment for this but the same exact code works on localhost. Because it is live with heavy traffic, I am reluctant to turn on debugging features that would show on front end.

Register post type code in functions.php

  $labels = array(
    'name' => _x('Supporters', 'post type general name'),
    'singular_name' => _x('Supporter', 'post type singular name'),
    'add_new' => _x('Add New', 'supporter'),
    'add_new_item' => __('Add New Supporter'),
    'edit_item' => __('Edit Supporter'),
    'new_item' => __('New Supporter'),
    'all_items' => __('All Supporters'),
    'view_item' => __('View Supporter'),
    'search_items' => __('Search Supporters'),
    'not_found' =>  __('No supporters found'),
    'not_found_in_trash' => __('No supporters found in Trash'), 
    'parent_item_colon' => '',
    'menu_name' => 'Supporters'

  );
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => true,
    'menu_position' => null,
    'taxonomies' => array ('beer','category'),
    'supports' => array('title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','page-attributes','revisions','comments','post-formats')
  ); 
  register_post_type('supporter',$args);

Register taxonomy code in functions.php

   // Add new taxonomy, make it hierarchical (like categories)
  $labels = array(
    'name' => _x( 'Supporters', 'taxonomy general name' ),
    'singular_name' => _x( 'Supporter', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Supporters' ),
    'all_items' => __( 'All Supporters' ),
    'parent_item' => __( 'Parent Supporter' ),
    'parent_item_colon' => __( 'Parent Supporter:' ),
    'edit_item' => __( 'Edit Supporter' ), 
    'update_item' => __( 'Update Supporter' ),
    'add_new_item' => __( 'Add New Supporter' ),
    'new_item_name' => __( 'New Supporter Name' )
  );

  register_taxonomy('supporter',array('beer','post'),
    array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'supporters-bp' )
  ));
0

2 Answers 2

1

Nevermind. For some reason, I had to go to my permalinks page and click 'Save Changes' for this to show up. It is bewildering.

2
  • I think that flushes the rewrite options in your htaccess. Every time that you add something like a new post type you have to do this or use add_action('admin_init', 'flush_rewrite_rules'); in order to flush the cache rewrite rules. ( from codex.wordpress.org/Custom_Queries ) Commented Sep 7, 2011 at 21:32
  • 4
    Important note, if adding to hook, that rules should be flushed once after changes.
    – Rarst
    Commented Nov 8, 2011 at 20:13
-3

You need to flush the Permalinks on post save.

You can add this function to the functions.php file:

// ==============================================
// Flush Permalinks on Save Post
// ==============================================

//Create a Function to Flush Permalinks
function nr_flush_permalinks() {
    /* Call WordPress rewrite function to flush rules.
        http://codex.wordpress.org/Rewrite_API/flush_rules */
    $wp_rewrite->flush_rules();
    // Do anything you wish to do more....
}
//Add Function "n_flush_permalinks()" to the "save_post" action hook:
add_action( 'save_post', 'nr_flush_permalinks()' );
3
  • 2
    On save_post? That’s not the proper action.
    – fuxia
    Commented Jun 6, 2014 at 17:05
  • 1
    Quoting directly from the 2nd ¶ of the flush_rules() Codex page: "Because this function can be extremely costly in terms of performance, it should be used as sparingly as possible - such as during activation or deactivation of plugins or themes. Every attempt should be made to avoid using it in hooks that execute on each page load, such as init." (emphasis mine)
    – Pat J
    Commented Jun 6, 2014 at 17:28
  • Copied from @Rarst comment on previous answer. "Important note, if adding to hook, that rules should be flushed once after changes. Commented Jun 6, 2014 at 17:53

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