<p>The problem was that there were validation failures that were silently failing. The mighty Brad's suggestion of <code>$entry-&gt;getErrors() after calling saveEntry()</code> let me see what the issue was.</p>

<p>Thanks Brad!</p>

CC BY-SA 3.0
2017-01-11T08:57:35.897Z
2017-01-11T08:57:35.897Z
John
<p>I haven't used <code>getEntryById</code>, and this isn't exactly an answer, but here is how I am doing pretty much the same thing:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'mySection');
$criteria-&gt;status = null;
$criteria-&gt;limit = 1;
$entry = $criteria-&gt;first();

...
if ($entry) {
    $entry-&gt;setContentFromPost([
        'myFieldHandle' =&gt; 'woot'
    ]);

    craft()-&gt;entries-&gt;saveEntry($entry);
} else {
    // Could not find entry.
}

...
</code></pre>

<p>Unless you are setting the page title, then I think you need to use something like:</p>

<pre><code>...
$entry-&gt;getContent()-&gt;title = 'woot';
</code></pre>

CC BY-SA 3.0
2017-01-11T04:04:11.090Z
2017-01-11T04:04:11.090Z
Damon
<p>So, i'm trying to set a fields content via a plugin on an entry which already exists.</p>

<p>My code is like this:</p>

<pre><code>$entry = craft()-&gt;entries-&gt;getEntryById($entryId);

$entry-&gt;setContentFromPost(array(
    'subTitle' =&gt; 'woot'
));

$success = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>I get no error and the value of <code>$success</code> is <code>false</code> but it tells me nothing else.
If I <code>var_dump($entry)</code> after the first line, the output shows it has pulled the correct entry.</p>

CC BY-SA 3.0
2017-01-10T16:41:41.997Z
I think `setContentFromPost` might be intended for when using forms with `$_POST` data (there are some underlying functions that trigger when using this method) . Have you tried just `$entry->setContent(array())`?
Alec Ritson
CC BY-SA 3.0
2017-01-10T22:09:56.197Z
I tried this: ```$entry->getContent()->subTitle = "woot"``` but didn't try set content! Thanks!
John
CC BY-SA 3.0
2017-01-11T03:41:00.223Z
Do you get anything if you call `$entry->getErrors()` after calling `saveEntry()`?
Brad Bell
CC BY-SA 3.0
2017-01-11T08:56:18.290Z
@BradBell Aha! There are validation errors, clearly some fields have been made required after the initial entry was saved. Thanks very much Brad!!!
John
<plugin-development>
Update existing entry from plugin not saving and producing no error
# Update existing entry from plugin not saving and producing no error

(Asked by: username_0 on 2017-01-10)

So, i'm trying to set a fields content via a plugin on an entry which already exists.
My code is like this:
$entry = craft()->entries->getEntryById($entryId);

$entry->setContentFromPost(array(
    'subTitle' => 'woot'
));

$success = craft()->entries->saveEntry($entry);

I get no error and the value of $success is false but it tells me nothing else.
If I var_dump($entry) after the first line, the output shows it has pulled the correct entry.

**Tags:** plugin-development

> **Comments:**
> **username_1**: I think `setContentFromPost` might be intended for when using forms with `$_POST` data (there are some underlying functions that trigger when using this method) . Have you tried just `$entry->setContent(array())`?  
> **username_0**: I tried this: ```$entry->getContent()->subTitle = "woot"``` but didn't try set content! Thanks!  
> **username_2**: Do you get anything if you call `$entry->getErrors()` after calling `saveEntry()`?  
> **username_0**: @BradBell Aha! There are validation errors, clearly some fields have been made required after the initial entry was saved. Thanks very much Brad!!!  

---

## 2 answers

### Answer by username_0 on 2017-01-11. Score: 1

The problem was that there were validation failures that were silently failing. The mighty Brad's suggestion of `$entry->getErrors() after calling saveEntry()` let me see what the issue was.

Thanks Brad!


---

### Answer by username_3 on 2017-01-11. Score: 1

I haven't used getEntryById, and this isn't exactly an answer, but here is how I am doing pretty much the same thing:
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'mySection');
$criteria->status = null;
$criteria->limit = 1;
$entry = $criteria->first();

...
if ($entry) {
    $entry->setContentFromPost([
        'myFieldHandle' => 'woot'
    ]);

    craft()->entries->saveEntry($entry);
} else {
    // Could not find entry.
}

...

Unless you are setting the page title, then I think you need to use something like:
...
$entry->getContent()->title = 'woot';


---

