I'm having a small issue creating a script that take in an entry_id, and based on that creates a new carbon copy entry with a new entry_id.

I've got this working, however as it stands now i'm forced to updated the $entry_data array everytime a new ee_channel_data field_id_# column is created.


$entry_data = array(
    'title' =>  $get_channel_title_res['title'] . ' COPY',
    'url_title' =>  $get_channel_title_res['url_title'] . '_copy',
    'entry_date' => $get_channel_title_res['entry_date'],
    'edit_date' =>  $get_channel_title_res['edit_date'],
    'field_id_1' => $get_channel_data_res['field_id_1'],
    'field_id_2' => $get_channel_data_res['field_id_2'],
    'field_id_3' => $get_channel_data_res['field_id_3']

ee()->api_channel_fields->setup_entry_settings($channel_id, $entry_data);               

$success = ee()->api_channel_entries->save_entry($entry_data, $channel_id);

I would prefer not to have to specify the fields, but simply tell EE's API Create a new entry, based on this old entry, and change it's title/url_title to appent _COPY.

I realize there's an addon for this, however that's not an option for me


1 Answer 1


Have you considered an answer like this?

$entry_data = array();

// select all column names from your exp_channel_data table
$col_names = ee()->db->query('SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='yourdatabasename' AND `TABLE_NAME`='exp_channel_data')->result_array();

foreach ($col_names as $column_name) {
    // conditionals
    switch ($column_name) {

        // don't add an entry_id, 'cause auto insertion (giggity)
        case "entry_id":

        // title string append
        case "title":
            $entry_data[$column_name] = $get_channel_title_res[$column_name] . ' COPY';

        // url_title string append
        case "url_title";
            $entry_data[$column_name] = $get_channel_title_res[$column_name] . '_copy';

        // add everything else
            if (isset($get_channel_title_res[$column_name])) {
                $entry_data[$column_name] = $get_channel_title_res[$column_name];

// continue along your merry way with your api wackery


There isn't a built in function to do what you're asking.

OK, what about something even simpler? Assuming you have the entry_id you want to clone...

// get old data
$entry_data = ee()->db->select()
                      ->where('entry_id', $entry_id)

// fix our copy
$entry_data["entry_id"]   = "";
$entry_data["title"]     .= " COPY";
$entry_data["url_title"] .= "_copy";

// move along, nothing to see here

Adds a database call but looks nicer!

  • I have, this was plan-B. I was just hoping that there's a cleaner way to do this via API call like ee()->api_channel_entries->copy_from($thisentry);
    – ipixel
    Oct 27, 2015 at 19:37
  • There isn't that functionality built in to the EE channel entries api. Sorry.
    – jrothafer
    Oct 27, 2015 at 19:56
  • and there is this devot-ee.com/add-ons/mx-cloner
    – Jim Wyse
    Oct 27, 2015 at 22:01
  • Yea, we try to stay away from addons, modules and extensions. I saw mx-cloner when researching how to duplicate entries. But that was not an option. Thanks though!
    – ipixel
    Oct 28, 2015 at 14:46

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.