I’m trying to register a CPT from a plugin upon activation but seem to have hit a wall… Anyone see anything im missing? I don’t get any errors but the CPT doesn’t show up in the dashboard links….
function ctg_cpt_init() {
register_post_type( 'ctg_questions',
array(
'labels' => array(
'name' => __( 'Questions' ),
'singular_name' => __( 'Question' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'questions' )
)
);
}
add_action( 'init', 'ctg_cpt_init' );
function ctg_rewrite_flush() {
ctg_cpt_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'ctg_rewrite_flush' );
Thanks,
Pull the CPT registration functionality out of the Plugin activation hook, so that it can fire at
init
, where you want it to.The Plugin activation hook is a one-time only hook; you need your CPT to fire every time at the
init
hook, not just once.