【发布时间】:2013-09-28 08:15:11
【问题描述】:
我正在尝试检查“categoryone”是否有父母。 知道我可以检查并看到有一个名为 categoryone 的类别,但如果 categoryone 有一个父类别,则不是。 我尝试编写类似下面的代码。
$tid = term_exists('categoryone', 'category', 0);
$term_ids = [];
if ( $tid !== 0 && $tid !== null )
{
$term_ids[] = $tid['term_id'];
}
else
{
// If there is not a parent category!
$insert_term_id = wp_insert_term( 'categoryone', 'category' );
if ( ! is_wp_error )
$term_ids[] = $insert_term_id;
}
wp_set_post_categories( $insert_id, $term_ids );
【问题讨论】: