<p>Okay, I think I figured it out. 1st, I added the getContent()</p>

<p>I changed</p>

<pre><code>    $entry-&gt;showName[] = 22;
</code></pre>

<p>to </p>

<pre><code>    $entry-&gt;getContent()-&gt;showName = 22;
</code></pre>

<p>I think the problem is that the category we had set up only allowed for a single value and I was responding with an array.</p>

<p>Someone please correct me if am wrong.</p>

CC BY-SA 3.0
2016-04-03T02:50:38.853Z
Now that I have solved the problem of assigning a single category I find myself stumped when assigning multiple categories. How do I pass an array of category ids into getContent()->showName?
David A McInnis
CC BY-SA 3.0
2016-04-08T21:01:18.243Z
getContent()->showName = array(10,1468,14,15,16);
David A McInnis
CC BY-SA 3.0
2016-04-02T21:34:49.023Z
2016-04-02T21:34:49.023Z
David A McInnis
<p>I am importing data into Craft. I happen to know that the id for my desired category is 22. The category is not being saved.</p>

<p>Here is my code.</p>

<pre><code>    $entry = new EntryModel(); 
    $entry-&gt;sectionId   = 3; // 3 is Episode Section
    $entry-&gt;enabled     = true;
    $entry-&gt;authorId    = 1;
    $entry-&gt;slug = $slug;
    $entry-&gt;postDate = $postDate;
    $entry-&gt;getContent()-&gt;title = $title;
    $entry-&gt;getContent()-&gt;body = $body;
    $entry-&gt;getContent()-&gt;summary = $summary;
    $entry-&gt;getContent()-&gt;metaDescription = $summary;
    $entry-&gt;showName[] = 22;
</code></pre>

<p>Where showName is the category handle of my category field.</p>

<categories><plugins>
Assign category through a plugin
# Assign category through a plugin

(Asked by: username_0 on 2016-04-02)

I am importing data into Craft. I happen to know that the id for my desired category is 22. The category is not being saved.
Here is my code.
    $entry = new EntryModel(); 
    $entry->sectionId   = 3; // 3 is Episode Section
    $entry->enabled     = true;
    $entry->authorId    = 1;
    $entry->slug = $slug;
    $entry->postDate = $postDate;
    $entry->getContent()->title = $title;
    $entry->getContent()->body = $body;
    $entry->getContent()->summary = $summary;
    $entry->getContent()->metaDescription = $summary;
    $entry->showName[] = 22;

Where showName is the category handle of my category field.

**Tags:** categories, plugins


---

## 1 answers

### Answer by username_0 on 2016-04-02. Score: 2 | Accepted answer

Okay, I think I figured it out. 1st, I added the getContent()
I changed
    $entry->showName[] = 22;

to 
    $entry->getContent()->showName = 22;

I think the problem is that the category we had set up only allowed for a single value and I was responding with an array.
Someone please correct me if am wrong.

> **Comments:**
> **username_0**: Now that I have solved the problem of assigning a single category I find myself stumped when assigning multiple categories. How do I pass an array of category ids into getContent()->showName?  
> **username_0**: getContent()->showName = array(10,1468,14,15,16);  

---

