Skip to main content
flush rules in theme
Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.


Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea.

Important:

  • Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest executing it on the init hook. This is bad practice. It should be executed either on the 'shutdown' hook, or on plugin/theme (de)activation.
  • Flush rules once (it's better to store the state in option, instead of activation or deactivation, because on MultiSite they are useless), or when you know that the rewrite rules need to be changed. Don't do it on any hook that will triggered on a routine basis. More detail information in the comments on WP Engineer's post: Custom Post Type and Permalink
  • Make sure custom post types and taxonomies are properly registered before flushing rewrite rules, especially during plugin activation: Activation Checklist for WordPress Plugin Developers (inaccessible)

Example

Flush rules on theme activation:

add_action( 'after_switch_theme', 'custom_taxonomy_flush_rewrite' );
function custom_taxonomy_flush_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.


Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea.

Important:

  • Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest executing it on the init hook. This is bad practice. It should be executed either on the 'shutdown' hook, or on plugin/theme (de)activation.
  • Flush rules once (it's better to store the state in option, instead of activation or deactivation, because on MultiSite they are useless), or when you know that the rewrite rules need to be changed. Don't do it on any hook that will triggered on a routine basis. More detail information in the comments on WP Engineer's post: Custom Post Type and Permalink
  • Make sure custom post types and taxonomies are properly registered before flushing rewrite rules, especially during plugin activation: Activation Checklist for WordPress Plugin Developers (inaccessible)

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.


Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea.

Important:

  • Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest executing it on the init hook. This is bad practice. It should be executed either on the 'shutdown' hook, or on plugin/theme (de)activation.
  • Flush rules once (it's better to store the state in option, instead of activation or deactivation, because on MultiSite they are useless), or when you know that the rewrite rules need to be changed. Don't do it on any hook that will triggered on a routine basis. More detail information in the comments on WP Engineer's post: Custom Post Type and Permalink
  • Make sure custom post types and taxonomies are properly registered before flushing rewrite rules, especially during plugin activation: Activation Checklist for WordPress Plugin Developers (inaccessible)

Example

Flush rules on theme activation:

add_action( 'after_switch_theme', 'custom_taxonomy_flush_rewrite' );
function custom_taxonomy_flush_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}
added 1072 characters in body
Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.


Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea.

Important:

  • Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest executing it on the init hook. This is bad practice. It should be executed either on the 'shutdown' hook, or on plugin/theme (de)activation.
  • Flush rules once (it's better to store the state in option, instead of activation or deactivation, because on MultiSite they are useless), or when you know that the rewrite rules need to be changed. Don't do it on any hook that will triggered on a routine basis. More detail information in the comments on WP Engineer's post: Custom Post Type and Permalink
  • Make sure custom post types and taxonomies are properly registered before flushing rewrite rules, especially during plugin activation: Activation Checklist for WordPress Plugin Developers (inaccessible)

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.


Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea.

Important:

  • Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest executing it on the init hook. This is bad practice. It should be executed either on the 'shutdown' hook, or on plugin/theme (de)activation.
  • Flush rules once (it's better to store the state in option, instead of activation or deactivation, because on MultiSite they are useless), or when you know that the rewrite rules need to be changed. Don't do it on any hook that will triggered on a routine basis. More detail information in the comments on WP Engineer's post: Custom Post Type and Permalink
  • Make sure custom post types and taxonomies are properly registered before flushing rewrite rules, especially during plugin activation: Activation Checklist for WordPress Plugin Developers (inaccessible)
Source Link
nmr
  • 4.5k
  • 2
  • 17
  • 25

You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.