Hi Max. Welcome to the EE forums 😊
You can check out the EE Dev Docs for info on using some of their built-in classes and whatnot. To add entries via PHP I’d suggest you take a look at the Channel Entries API section.
I created template Some/test with allow php. I set code in template as
<?php
$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');
$data = array( 'title' => 'New entry',
'custom_field1' => 'test1',
'entry_date' => '1293673800',
'alternative_header'=>'new entry' );
if ($this->EE->api_channel_entries->submit_new_entry(1, $data) === TRUE) {echo ('All Ok'); }
?>When I’m in browser load url site.com/some/test I have message “All Ok”, but entry isn’t created. What’s my mistake?
If i disable extensions - it isn’t work properly. I see database - there are new record in table ‘exp_channel_data’, but all field in record is NULL(except channel_id, entry_id. it’s correct channel_id in database record) (if I create record manually using Content/Publish - there are some field not NULL in record)
How to create entry with different then English language in field ? For example:
$data = array('title' => 'Title',
'entry_date' => time()
);
$this->EE->api_channel_entries->submit_new_entry(1, $data)return TRUE
// title => text in Russian
$data = array('title' => 'Тайтл',
'entry_date' => time()
);
$this->EE->api_channel_entries->submit_new_entry(1, $data)return FALSE
EE using utf-8 as default charset and utf-8 as DB charset (if I try add entry manually adding record to DB - all ok)
Upd1: It’s problem with _validate_url_title in Api_channel_entries.php and return error string “unable_to_create_url_title” Maybe, it’s some problem with DB charset Upd2: I not implement url_title If I implement url_title all ok. Problem solved. Thanks
Awesome troubleshooting in this thread 😊 .
How do I get entry_id from created entry ?
Your solution will work most of the time, but there’s no guarantee that entry ids will be sequential. I’m a little surprised that it doesn’t return the id. I’ll look into that, but for now try this right after the insert:
$this->EE->api_channel_entries->entry_id;Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.