You'll need to create a new table/record to store the data
class IdRecord extends BaseRecord
{
/**
* Returns the name of the database table the model is associated with (sans table prefix). By convention,
* tables created by plugins should be prefixed with the plugin name and an underscore.
*
* @return string
*/
public function getTableName()
{
return 'ids';
}
/**
* Returns an array of attributes which map back to columns in the database table.
*
* @access protected
* @return array
*/
protected function defineAttributes()
{
return array(
'oldId' => AttributeType::Number,
'newId' => AttributeType::Number
);
}
}
Create a new Controller and store with the record
public function actionCreateTag()
{
$this->requireLogin();
$this->requireAjaxRequest();
$tag = new TagModel();
$tag->groupId = craft()->request->getRequiredPost('groupId');
$tag->getContent()->title = trim(craft()->request->getRequiredPost('title'));
$oldId = craft()->request->getRequiredPost('oldId');
if (craft()->tags->saveTag($tag))
{
$tagMap = new IdRecord();
$tagMap->oldId = $oldId;
$tagMap->newId = $tag->id;
$tagMap->save();
$this->returnJson(array(
'success' => true,
'id' => $tag->id
));
}
else
{
$this->returnJson(array(
'success' => false
));
}
}
And when you are saving your entries you'll do
$entry = new EntryModel();
// ... set your content
$oldId = 'number of your old WP tag id';
$tag = IdRecord::model()->find('oldId = :oldId',[
'oldId' => $oldId
]);
$entry->getContent()->setAttribute('yourTagFieldHandle', $tag->newId);
You can use pluginfactory.io to create your boilerplate.
Edit
Another approach. If you receive the title of the tags as an array like ['tag1', 'tag2', 'tag3']
would be something like
$ids = [];
foreach($tagTitles as $tagTitle){
$criteria = craft()->elements->getCriteria(ElementType::Tag);
$criteria->title = 'your Tag Title';
$tag = $criteria->first();
if($tag){
$ids[] = $tag->id;
}
}
$entry->getContent()->setAttribute('yourFieldHandle', $ids);