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.


Okay, I think I figured it out. 1st, I added the getContent()

I changed

    $entry->showName[] = 22;


    $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.

  • 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? Apr 3 '16 at 2:50
  • getContent()->showName = array(10,1468,14,15,16); Apr 8 '16 at 21:01

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.