I am creating an article in Joomla 4 using the excellent code that is suggested here: Joomla 4 create article programmatically My task is write the values of the custom field simultaneously with the creation of the article. The search for a solution leads only to results for Joomla 3. I ask for help for Joomla 4

1 Answer 1


In case you're referring to this answer, you can add com_fields array to the data array before passing it to model's save() method:

$article = [
    'title' => 'article title',
    'catid' => 2',
    'com_fields' => [
        'test-field' => 'field value',

if (!$articleModel->save($article)){
    throw new Exception($articleModel->getError());

However, this may not work if you're not logged in as user with field editing permissions. This is because Joomla does not adhere to its advertised MVC architecture. In this case, permission check is performed by the field model when in reality it should be the responsibility of the controller.

  • It is working! Thank you very much! Your answer has made my work much easier. Unfortunately, I can't increase the usefulness of the answer. My reputation doesn't allow it.
    – Igor K.
    Aug 24, 2023 at 19:09
  • IgorK. If this answer helped you get your code working then please accept the answer. This will acknowledge the effort @Sharky has put in to helping you and your own reputation will increase as a result.
    – Irata
    Aug 29, 2023 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.