jjgrainger / wp-custom-post-type-class

A PHP Class for creating Wordpress Custom Post Types easily
MIT License
416 stars 114 forks source link

Won't register on add_action('init') #61

Closed torrfura closed 8 years ago

torrfura commented 8 years ago

When I try to use this class in a custom plugin, it won't register on add_action('init'). I need to use add_action('plugins_loaded') to get it to register, but that doesn't feel ok.

If I replace $book->CPT(...) with wordpress own register_post_type, it works on add_action('init').

Any ideas?

jjgrainger commented 8 years ago

The class uses add_action('init') to register the post type on its own, so you won't need to do it yourself.

If you're using a class for your plugin best thing to do is just call a custom function to register the post type.

class Plugin {

    function __construct() {
        $this->register_post_type();
        // and anything else
    }

    function register_post_type() {
        $this->CPT = new CPT('book');
        $this->CPT->register_taxonomy('genre');
    }

    //...
}