我注册的自定义分类名称是ov-category
.. 已存在名为Gender
现在我想添加一个名为Male
:
$parent_term = term_exists( \'Gender\', \'ov-category\' );
$parent_term_id = $parent_term[\'term_id\']; // get numeric term id
echo $parent_term_id; // shows the correct parent ID, that means term_exists() does work!!
// Inserting the child term \'Male\'
wp_insert_term(
\'Male\', // the term
\'ov-category\', // the taxonomy
array(
\'description\'=> \'\',
\'slug\' => \'\',
\'parent\'=> $parent_term_id
)
);
即使我尝试插入一个仅限家长的术语,它也不起作用。但我可以使用term\\u exists()读取正确的ID,这些ID是正确的,因为我在数据库中检查了它们。顺便说一下:我补充道Gender
通过UI。我需要一种在安装插件时自动添加这些术语的方法。