Php WordPress:触发post_保存时添加新类别
我是wordpress插件开发的新手。 我想在管理员创建新的自定义帖子类型时添加一个新类别。 这是我的密码:Php WordPress:触发post_保存时添加新类别,php,wordpress,plugins,custom-post-type,Php,Wordpress,Plugins,Custom Post Type,我是wordpress插件开发的新手。 我想在管理员创建新的自定义帖子类型时添加一个新类别。 这是我的密码: define('POSTTYPE', 'box'); add_action('save_post_' . POSTTYPE, array('controller', 'add_new_category_when_new_box_created'), 10, 3); class controller { static function add_new_category_when
define('POSTTYPE', 'box');
add_action('save_post_' . POSTTYPE, array('controller',
'add_new_category_when_new_box_created'), 10, 3);
class controller
{
static function add_new_category_when_new_box_created($post_id, $post,
$update)
{
if (get_post_type() == POSTTYPE) {
//only new box create category no updated one
if ($update)
return false;
$post_title = $post->post_title;
wp_create_category($post_title);
return true;
}
return false;
}
}
问题是,$update即使在我创建新帖子时也是正确的。你的分类名称是什么?@DevDanidhariya我还不熟悉分类法,但可能我没有使用它。