How can I iterate channel entries?
Basically what I’d like to use is a function to get channel entries that can be used like this:
$entry_id = ...
$data = $ee->api_channel_entries->get_entry($entry_id)
$data['field_id_10'] += 1;
$ee->api_channel_entries->update_entry($entry_id, $data);or
$entry_id = ...
$data = $ee->api_channel_entries->get_entry($entry_id)
$data['title'] = 'Copy of ' . $data['title']
$data['url_title'] = 'copy-of-' . $data['url_title']
$ee->api_channel_entries->submit_new_entry($data['channel_id'], $data);To get entries I’ve tried using
$ee->db->where('entry_id', $entry_id);
$ee->db->select(array('field_id_1', 'field_id_2')); // field_id_3, etc...
$ee->db->from('channel_data');But I can’t pass that data to submit_new_entry or update_entry.
From what I understand, submit_new_entry (and probably update_entry as well), sends the data through the custom field functions, before saving it in the database. For example saving data to a Playa field: array(‘selections’ => array(”, 123), ‘old’ => “”)
But reading it back gives: “[123] Title” Using that string in submit_new_entry results in errors.
Seems like you’re having trouble because get_entry() might not be returning the right kind of object that submit_new_entry() needs. My guess is that your entry object might be missing a channel_id property.
Why don’t you find out how the control panel does it? Open up system/expressionengine/controllers/cp/content_publish.php, find the _submit_new_entry() method and var_dump the $data parameter being passed in the methods…
$this->api_channel_entries->update_entry(…) and $this->api_channel_entries->submit_new_entry(…)
See what the hell they’re doing.
Also, in my experience I couldn’t get submit_new_entry() to work with Playa or Matrix fields. I’d just get php errors. Seems to be an EE bug: http://ellislab.com/forums/viewthread/167065/ which might have been fixed in the latest build.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.