register-post类型没有';不起作用


register post type doesn't work

register-post类型在我的wordpress中不起作用。

这是所有的代码。

register_activation_hook( __FILE__, array( 'Cp_Setup', 'cpActivatePlugin' ) );
class Cp_Setup{
public static function init(){
}
public function cpActivatePlugin(){
    self::_cpCreateCustomPostType();
}
// Registering Custom Post Type if it isn't already registered.
private function _cpCreateCustomPostType(){
    $labels = array(
            'name' => __( 'Custom Posts' ),
            'singular_name' => __( 'Custom Post' ),
            /* etc. */ 
            'parent_item_colon' => __( 'Parent Page (Custom Post)' )
    );
    $args = array(
            'labels' => $labels,
            'public' => true,
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),
            'taxonomies' => array( '' ),
            'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
            'has_archive' => false
    );
    register_post_type('cp_custom_post',$args);
}
}

但是上面的代码没有注册任何名为"cp_custom_post"的post类型。

_cpCreateCustomPostType()需要在每个请求上运行;不仅仅是当你激活插件的时候。钩入init钩子,或者通常使用的任何钩子来注册自定义post类型。