If I register my custom post type when the init action fires (which is before plugin activation) why do I need to register my custom post type a second time when flushing rewrite rules (on plugin activation)? See the following example.

add_action( 'init', 'my_cpt_init' );
function my_cpt_init() {
    register_post_type( ... );

function my_rewrite_flush() {
register_activation_hook( __FILE__, 'my_rewrite_flush' );

1 Answer 1


When a plugin is activated, the only thing that runs on that activation request is the activation hook. whatever you've got hooked to init has not and will not run on that request, so you need to register it in your activation before you flush rewrites. it's only after the plugin is activated, on the next request, that the init action fires for that plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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