Reputation: 6370
I'm trying to add two strings as custom taxonomy terms using the following:
$breadcrumbgrandparent = strip_tags($html->find('div[class=breadcrumb-panel] ul li', 1));
$breadcrumbparent = strip_tags($html->find('div[class=breadcrumb-panel] ul li', 2));
$tags = $breadcrumbgrandparent . ", " . $breadcrumbparent;
// vars
$my_post = array(
'post_title' => $strippedtitle, //site
'post_type' => 'product',
'post_status' => 'publish',
);
// insert the post into the database
$post_id = wp_insert_post( $my_post );
$taxonomy = 'categories';
wp_set_object_terms($post_id, $tags, $taxonomy);
At the moment it's adding the strings as one term called "Term 1, Term 2" rather than two separate terms called "Term 1" and "Term 2".
Where am I going wrong?
Upvotes: 0
Views: 810
Reputation: 3572
The problem is in $tags value. It should be an array, but you are using imploded string.
Try this:
wp_set_object_terms($post_id, explode(",",$tags), $taxonomy);
Upvotes: 1