对于非层次术语(如标记),可以传递术语名称或id。如果传递id,则只有一个警告:必须以整数形式传递,并且必须在数组中。这是必要的,因为传递的任何非数组值都将转换为字符串,该字符串将被解释为术语名称。
$tag = \'5\'; // Wrong. This will add the tag with the *name* \'5\'.
$tag = 5; // Wrong. This will also add the tag with the name \'5\'.
$tag = array( \'5\' ); // Wrong. Again, this will be interpreted as a term name rather than an id.
$tag = array( 5 ); // Correct. This will add the tag with the id 5.
wp_set_post_terms( $post_id, $tag, $taxonomy );
此函数仅适用于本机post类型。