WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hitting a brick wall with the following:

I have:

  • 1 custom post type called cpt_community
  • 1 custom taxonomy called tax_community

If I set 'rewrite' => true in my CPT registration, then permalinks to an entry for this CPT are of the form of http://<domain>/cpt_community/test_item/, and I get a 404 when browsing to it.

If I set 'rewrite' => false, then permalinks are http://<domain>/?cpt_community=test_item/, and this works fine.

So, I'm obviously doing something wrong/stupid - the question is, what?


  • After every change I'm flushing rules by going to Settings > Permalinks (and saving)
  • After leaving everything alone for an hour, things have started working correctly - so why the delay?


CPT Registration

function community_post_type() {
  $labels = array('name'  => 'Community');

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

  register_post_type('cpt_community', $args);
add_action( 'init', 'community_post_type' );

Custom Taxonomy Registration

function community_tax_type() {
     array( 'hierarchical' => false,
       'label' => 'Community Content Type',
       'show_ui' => true,'query_var' => true,
       'rewrite' => true,
       'singular_label' => 'Community Content Type',
       'capabilities' => array('assign_terms' => 'edit_community_tags')
   # allow roles to add community taxonomy tags to a community CPT
   $roles = array("subscriber","contributor","author","editor","administrator");

   foreach ($roles as $role_name) {
     $role = get_role($role_name);
add_action( 'init', 'community_tax_type' );
share|improve this question
you've flushed rewrites first by visiting permalinks page and saving? – Milo Jul 17 '11 at 15:26
@milo - yup. Interestingly, after walking away for an hour and then coming back, the 'pretty permalinks' are now working - I'll update the question and frame it as a 'why the delay' – anu Jul 17 '11 at 15:33
Do you use a caching plugin? Does it work faster with all other plugins disabled? (Just getting the usual suspects out of the way) – Jan Fabry Jul 18 '11 at 21:21
@jan - no caching plugin. The problem is that I can't reproduce this behaviour - it's happened a couple of times now and goes away after but with no specific action (that I can tell) to actually fix it. – anu Jul 19 '11 at 13:42

Use the function flush_rewrite_rules() for set the rewrite rules new, but not with your code on init-hook, only on activation plugin or theme! See more in my post: http://wpengineer.com/2044/custom-post-type-and-permalink/

And an example on this Gist: https://gist.github.com/978690

        global $wp_rewrite;

via Hook

share|improve this answer

Just go to Settings>Permalinks to flash the rules. No code is needed. You don't need to update the structure, just opening that admin page does the job

share|improve this answer
but you then have to visit that page every time an error occurs. By using the flush_rewrite_rules(); function means they get flushed with no real need for interaction. – Alex Older Mar 26 '12 at 13:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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