我理解你的问题,也必须解决它:wp_insert_term() 不处理父/子连接。
您可以通过以下内容进行检查:
$tax = \'category\';
$terms = get_terms( array( $tax ) );
$children_to_update = array();
foreach ( $terms as $term )
{
    $checked_term = get_term_by( \'name\', $term, $tax );
    // ... retrieve parent here ...
    if ( ! $checked_term )
    {
        $term_data = wp_insert_term(
            $term,
            $tax,
            array( \'parent\' => $parent )
        );
        if (
            is_array( $term_data )
            AND ! is_wp_error( $term_data )
            AND \'0\' !== $parent
        )
            $children_to_update[ $parent ][] = $term_data[\'term_id\'];
    }
}
// inspect result
var_dump( $children_to_update );
 你会看到它一直是空的。原因很简单:有一个
Option 保存此信息的。您还需要更新它:
$option = get_option( "{$tax}_children" );
foreach( $children_to_update as $new_p => $new_c )
{
    if ( ! array_key_exists( $new_p, $option ) )
    {
        $option[ $new_p ] = $new_c;
    }
    else
    {
        foreach ( $new_c as $c )
        {
            if ( ! in_array( $c, $option[ $new_p ] ) )
                $option[ $new_p ][] = $c;
        }
    }
}
update_option( "{$tax}_children", $option );
 起初,我不知道层次结构不起作用,但当你在管理UI中查看分类法概述页面时,你会发现这些术语没有像should(在子/父列表中)那样对齐。