Finding entry by content I'm currently creating a plugin for craft and have stumbled across a slight problem. I'll try summarise of what I am doing and what I am trying to achieve.

So, I'm trying creating a plugin which will update entries within craft via an external API. I have managed to get the initial save to work using these following lines:

$entry = new EntryModel();
$entry-&gt;getContent()-&gt;title = $project-&gt;name;
$entry-&gt;sectionId = 10;
craft()-&gt;entries-&gt;saveEntry($entry);


The issue arises when I'm trying to update the model. Obviously, I don't want to duplicate entries.

I can get the entry using this line:

EntryRecord::model()-&gt;findById(45);


(this is just used for testing, eventually I will be getting the record via a custom variable).

What I'm trying to do here is update the title of this record, from what I can see this is stored in the craft_content table.

Basically what I'd like to do is something like :

EntryModel::model()-&gt;findByAttributes(array('title'=&gt;$project-&gt;name);


So I can then update the content title of that row.
I can see I can't do it this way, would you be able point me in the right direction?
It sort of depends on what information you have to identify the entry. If your external service knows the entry id that would be the most direct — otherwise you would have to find the entry by some other unique property.

To update an entry (given $entryId, $newTitle):

$entry = craft()-&gt;entries-&gt;getEntryById($entryId);
if ($entry) {
    $entry-&gt;getContent()-&gt;setAttributes(array(
        'title' =&gt; $newTitle
    ));
    craft()-&gt;entries-&gt;saveEntry($entry);
}


To update an entry (given $sectionHandle, $title, and $newTitle - or other unique property):

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = $sectionHandle;
$criteria-&gt;title = $title;
$entries = craft()-&gt;elements-&gt;findElements($criteria);

foreach ($entries as $entry) {
    $entry-&gt;getContent()-&gt;setAttributes(array(
        'title' =&gt; $newTitle
    ));
    craft()-&gt;entries-&gt;saveEntry($entry);
}


Could also use the 'search' method (although less reliable):

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;search = 'fieldHandle:searchstring';


In the last two cases, would need to handle the possibility that more than 1 entry is returned.

Also, when creating entries might want to include the authorId and typeId, in addition to sectionId:

$entry = new EntryModel();
$entry-&gt;sectionId  = $sectionId
$entry-&gt;typeId     = $typeId
$entry-&gt;authorId   = $authorId;
$entry-&gt;enabled    = true;
$entry-&gt;getContent()-&gt;setAttributes(array(
    'title' =&gt; $title
));
craft()-&gt;entries-&gt;saveEntry($entry);