Skip to content

Instantly share code, notes, and snippets.

@CreativePoweredGeek
Created September 19, 2020 19:05
Show Gist options
  • Save CreativePoweredGeek/e74e1544fd8cfcb5f0921e6d8cfd57ee to your computer and use it in GitHub Desktop.
Save CreativePoweredGeek/e74e1544fd8cfcb5f0921e6d8cfd57ee to your computer and use it in GitHub Desktop.
//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);
//Can also do:
//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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment