小编Mel*_*Dev的帖子

激活插件时创建自定义帖子类型并在停用后删除 -Wordpress

我希望我的插件在激活时自动创建自定义帖子类型。

这是我的代码

register_activation_hook(__FILE__, 'activate_myplugin');

function activate_myplugin() {

add_action('init', 'create_custom_type_post');

function create_custom_type_post() {

register_post_type('customposttype', array(
    'label' => 'my custom type post',
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array(
        'slug' => 'mycustomposttype',
        'with_front' => false
        ),
    'query_var' => true,
    'supports' => array(
        'title',
        'editor',
        'excerpt',
        'trackbacks',
        'custom-fields',
        'revisions',
        'thumbnail',
        'author',
        'page-attributes'
        )
    )
);
}
Run Code Online (Sandbox Code Playgroud)

}

以及停用时如何将其删除?

php wordpress custom-post-type

3
推荐指数
1
解决办法
3575
查看次数

标签 统计

custom-post-type ×1

php ×1

wordpress ×1