I'm trying to add entries to a Matrix block with one field type of 'entry' using the following:

$block = new MatrixBlockModel();
$block->fieldId    = 9;             // Matrix field's ID
$block->ownerId    = $collectionID; // ID of entry the block should be added to
$block->typeId     = 2;             // ID of block type
    'contentRss' => array($entry->id)

$success = craft()->matrix->saveBlock($block);

The code saves the new block and entry, but when I view the entry it has not linked the entry. I notice in the database tables it has not created an entry in the craft_relations table.

Where am I going wrong? :)


Possibly a duplicate of this one here but hey, here is where I think you are going wrong:

Change this part:

  'contentRss' => array($entry->id)

To this:

$block->getContent()->contentRss = array($entry->id);
  • No worries, did it work? Jul 29 '14 at 5:26
  • Excellent! In which case could you mark this answer as correct to better help out other people? Jul 30 '14 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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