0

In EE2 I used the channel entries API to create and update entries. In EE5 I can't use it anymore. The only problem is that I can't find any EE5 API functions to create those entries. Are they gone?

How can I create/update entries in EE5 without using the the legacy channel entries API? I can't find it in de docs.

0

2 Answers 2

0

You can still do this:

$entry = ee('Model')->make('ChannelEntry', $data);
$entry -> save();

Just make sure you have all the required info in the $data array.

0

You can create and update the Channel Entry using below Model query.

For Creating the Entry :-

$entry = ee('Model')->make('ChannelEntry');
$entry->Channel = $channel;
$entry->site_id =  ee()->config->item('site_id');
$entry->author_id = ee()->session->userdata('member_id');
$entry->ip_address = ee()->session->userdata['ip_address'];
$entry->versioning_enabled = $channel->enable_versioning;
$entry->sticky = FALSE;
$entry->title = $title_url_title;
$entry->url_title = preg_replace("/[\s_]/", "-", $title_url_title);
$entry->entry_date = ee()->localize->now;
$entry->edit_date = ee()->localize->now;
$entry->save();

/* Array which contains your Field Data */
$entry->set($entryFieldArray);

For Updating the Entry :-

$entry = ee('Model')->get('ChannelEntry', $id)
        ->with('Channel')
        ->filter('site_id', ee()->config->item('site_id'))
        ->first();

/* Array which contains your Field Data which need to update */
$entry->set($entryFieldArray);
1
  • awesome! I never know I had to use the Model service. Thanks for the tip!
    – Erwin
    Commented Mar 22, 2019 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.