我要做的是为自定义帖子类型分配一个层次术语:
function create_frontles_posts() {
$x = 1;
do {
$post_id = wp_insert_post(array(
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
\'post_author\' => 1,
\'post_name\' => \'Tile\'.$x,
\'post_title\' => \'Tile\',
\'post_status\' => \'publish\',
\'post_type\' => \'frontiles\',
));
wp_set_object_terms($post_id, array(\'mosaic-home\'), \'tiles_categories\', true);
$x++;
} while ($x <= 24);
}
我实现了自动生成24个自定义帖子,但无法在该过程中为它们指定术语。之前,我使用此函数创建了术语,没有问题:function example_insert_category() {
wp_insert_term(
\'Mosaic - Home\',
\'tiles_categories\',
array(
\'description\' => \'Add Tiles here to load in first term\',
\'slug\' => \'mosaic-home\'
)
);
}
add_action(\'init\',\'example_insert_category\');
我做错了什么?