我这样做的方式是通过term\\u id not slug,它可以工作:
//insert Art items into database
$arr = array(\'item 1\', \'item 2\');
// $arr = array(\'art item 1\', \'art item 2\');
foreach ($arr as $a) {
wp_insert_post(array(
//essentials
//\'ID\' => 1131,
\'post_author\' => 1,
\'post_title\' => $a,
\'post_type\' => \'post\',
\'post_content\' => \'Something...\',
\'post_status\' => \'publish\',
\'post_name\' => \'post name\',
\'meta_input\' => array( //(array) Array of post meta values keyed by their post meta key. Default empty.
\'city\' => \'\',// \'name\' => $post[\'name\']
\'country\' => \'\'// \'city\' => $post[\'city\']
),
\'tax_input\' => array(
\'category\' => array(33,32), //id numbers work, slugs tend to be ignored !!!
\'post_tag\' => array(\'one\', \'two\') //for tags slugs seem to work
),//(array) Array of taxonomy terms keyed by their taxonomy name. Default empty. Equivalent to calling wp_set_post_terms() / wp_set_object_terms()
//\'tags_input\' => array(\'una\', \'trei\'), //(array) Array of tag names, slugs, or IDs. Default empty. Equivalent to calling wp_set_post_tags().
), true);
}