I have a custom component, from which I am taking my data & creating a new article with extra field values(from code). Below, is my code & attempt.
JLoader::import('components.com_content.models.article', JPATH_ADMINISTRATOR); $app = JFactory::getApplication(); // Get the model $model = $this->getModel("lists"); $newsLists = $model->getNewsList(); foreach ($newsLists as $news) { $articleModel = ""; $articleModel = JModelLegacy::getInstance('Article', 'ContentModel'); $data = array(); $data['title'] = trim($news->title); $data['state'] = trim($news->state); $data['language'] = '*'; $data['catid'] = '221'; $data['com_fields']['title'] = trim($news->title); $data['com_fields']['source'] = trim($news->publication); $data['com_fields']['page-no'] = trim($news->pageno); $data['com_fields']['link'] = trim($news->externalurl); $data['com_fields']['attributes'] = trim($news->attributes); $data['com_fields']['downloads'] = trim($news->newsfile); $data['com_fields']['date-free-text'] = trim($news->published_date); $data['com_fields']['state'] = trim($news->state); $articleModel->save($data); } Actually, it creates the article correctly in the database(in Joomla 'content' table) but it only saves the single extra field value of 'title' ($data['com_fields']['title']) in Joomla fields_value table.
Code when I print $data;
Array ( [title] => unveils [state] => 2 [language] => * [catid] => 221 [com_fields] => Array ( [title] => unveils [source] => [page-no] => [link] => images/news/unveils.pdf [attributes] => [downloads] => [date-free-text] => [state] => 2 ) ) Array ( [title] => Workshop [state] => 1 [language] => * [catid] => 221 [com_fields] => Array ( [title] => Workshop [source] => [page-no] => [link] => /images/news/workshops.pdf [attributes] => [downloads] => [date-free-text] => 20.04.2015 [state] => 1 ) ) What's the wrong in foreach loop? Note : all the extra fields are already created from "Content >> Fields"