我试图在激活时从插件注册CPT,但似乎遇到了问题。。。有人看到我丢了什么吗?我没有收到任何错误,但CPT没有显示在仪表板链接中。。。。
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\' );
谢谢你,
最合适的回答,由SO网友:Chip Bennett 整理而成
将CPT注册功能从插件激活挂钩中拉出,以便在init, 在你想要的地方。
插件激活挂钩是一次性挂钩;您需要您的CPT在init 胡克,不止一次。