-
- How to Add a User to a Joomla Group Programmatically
- How to Send Emails in Joomla with PHP
- How to Connect to an External Database in Joomla with PHP
- How to Check if the Current Page Is the Homepage in Joomla with PHP
- How to Check If the Current User is Super User in Joomla with PHP
- How to Create a User Account in Joomla with PHP
- How to Create an Article in Joomla with PHP
- PHP Scripts Collection
How to Create an Article in Joomla with PHP
Below, you can find a PHP snippet that allows you to create a new article by providing a title, alias, intro, full text, and the category and its state.
$app = \Joomla\CMS\Factory::getApplication();
$mvcFactory = $app->bootComponent('com_content')->getMVCFactory();
$articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]);
$article = [
'catid' => 2,
'alias' => \Joomla\CMS\Filter\OutputFilter::stringURLSafe('A41234My Article Title'),
'title' => '123My Article Title',
'introtext' => 'My Article Intro Text',
'fulltext' => 'My Article Full Text',
'state' => 1,
'language' => '*',
];
if (!$articleModel->save($article))
{
throw new Exception($articleModel->getError());
}
Last updated on Apr 23rd 2025 14:04