我首先通过wp\\u set\\u object\\u terms设置要发布的术语,然后在term\\u分类表中运行更新查询,并将第二个术语的父id设置为第一个术语。
$taxo = wp_set_object_terms( $news_arr[0], utf8_encode($news_arr[2]), \'vehicle_models\', $append = false ) ;
$child = wp_set_object_terms( $news_arr[0], utf8_encode($news_arr[3]), \'vehicle_models\', $append = true ) ;
$category_parent = get_term_by(\'name\', $news_arr[2], \'vehicle_models\');
$category_child = get_term_by(\'name\', $news_arr[3], \'vehicle_models\');
$category_parent_id = $category_parent->term_id;
$category_child_id = $category_child->term_id;
$wpdb->update(
$wpdb->prefix.\'term_taxonomy\',
array(
\'parent\' => $category_parent_id,
),
array( \'term_id\' => $category_child_id )
);