What I want to do is assign a hierarchical term to a custom post type:
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);
}
I achieve making automatically that 24 custom posts but no way to assign them the term in that process. Before, I created the term with this function, with no problem:
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');
What I'm doing wrong?