Skip to content

Instantly share code, notes, and snippets.

@mattboon
Created May 18, 2011 09:17
Show Gist options
  • Save mattboon/978263 to your computer and use it in GitHub Desktop.
Save mattboon/978263 to your computer and use it in GitHub Desktop.
Guide Custom Post Type
<?php
// CUSTOM POST TYPE
add_action('init', 'matt_guide_register');
function matt_guide_register() {
$labels = array(
'name' => _x('Guide', 'post type general name'),
'singular_name' => _x('Region', 'post type singular name'),
'add_new' => _x('Add new region', 'region item'),
'add_new_item' => __('Add new'),
'edit_item' => __('Edit region'),
'new_item' => __('New region'),
'view_item' => __('View region'),
'search_items' => __('Search regions'),
'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,
'capability_type' => 'page',
'hierarchical' => true,
'menu_position' => null,
'rewrite' => array('slug' => 'guide', 'with_front' => true),
'supports' => array('title','editor','thumbnail','page-attributes','revisions')
);
register_post_type( 'guide' , $args );
}
?>
@ashfame
Copy link

ashfame commented Nov 1, 2011

You shouldn't flush_rewrite_rules() on every page load. Its required only once and calling it every time is a performance hit as it will write to database every time.

@mattboon
Copy link
Author

mattboon commented Nov 1, 2011

Yeah dude you're right. Found out when I published the site (which had 9 custom post types therefore 9 x flush rewrites!)

It was slow as hell and had discovered that to be causing it.

@ashfame
Copy link

ashfame commented Nov 1, 2011

One more suggestion, instead of adding it once to the file and then loading a page to flush the rewrite rules, you can simply visit the permalinks setting page. It does that too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment