2

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,

  • I tried your code and the CPT showed up in the Administration Panels primary navigation menu. Do you mean that you're trying to get it to show up in the 'Right Now' meta box on the dashboard? – Ian Dunn Jul 12 '11 at 17:44
  • 1
    Now she's working for me too! I changed the function namespaces before posting here - must've had a keying error. Thanks for everyones help and appologies for the time waster... – Peter Gibbons Jul 12 '11 at 18:03
1

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.

  • He's calling register_post_type() inside a hook to 'init'. He's only flushing the rewrite rules during the register_activation_hook(). – Ian Dunn Jul 12 '11 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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