Programmatically update entry field I'm trying to update an entry's field value from a Craft plugin. First I was trying to just update the attributes of the entry like so:

$entry-&gt;getContent()-&gt;setAttributes(array(
  'metaStatus' =&gt; 'Declined'
));

craft()-&gt;entries-&gt;saveEntry($entry);


But that wouldn't work because getContent doesn't return the data needed in order for the EntryModel to pass validation. The next solution was to loop through each of the fields and grab their field value like so:

$fields = array();

foreach($entry-&gt;getFieldLayout()-&gt;getFields() as $layout) {
  $handle = $layout-&gt;getField()-&gt;handle;

  $fields[$handle] = $entry-&gt;getFieldValue($handle);
}

$fields['metaStatus'] = 'Declined';

$entry-&gt;setContent($fields);

craft()-&gt;entries-&gt;saveEntry($entry); // FAIL


Now I'm having issues with matrix/asset fields validating since they come back as empty. Am I going to have to look for matrix/asset fields in my loop above and correctly format the data? There must be an easier way to do this.
I got around this issue by looping through all fields that were of BaseElementFieldType re-setting them to their current value.

$fields = $entry-&gt;getFieldLayout()-&gt;getFields();

$referentialFields = array();
foreach ($fields as $layoutField) {
  $field = $layoutField-&gt;getField();
  if ($field-&gt;getFieldType() instanceof BaseElementFieldType) {
    $referentialFields[$field-&gt;handle] = $entry-&gt;{$field-&gt;handle}-&gt;ids();
  }
}

$entry-&gt;setContentFromPost(array_merge($referentialFields, array(
  'yourField' =&gt; 'yourValue'
)));

craft()-&gt;entries-&gt;saveEntry($entry);