/** * Create taxonomy terms from entry * * @param integer $postId * @param EntryInterface $entry * * @return array of term ids */ protected function createTermsFromEntry($postId, EntryInterface $entry) { $ids = []; foreach ($entry->getCategories() as $category) { $term = term_exists($category['term'], $this->entryParams['taxonomy']); if ($term === 0 || $term === null) { $term = wp_insert_term($category['term'], $this->entryParams['taxonomy']); if (is_array($term)) { if (is_callable($this->entryParams['afterInsertTerm'])) { call_user_func($this->entryParams['afterInsertTerm'], $term['term_id']); } } } $ids[] = (int) $term['term_id']; } if (!empty($ids)) { wp_set_post_terms($postId, $ids, $this->entryParams['taxonomy']); } }