Skip to main content
Remove redundant WordPress from title
Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

WordPress save Save values from foreach loop in wp_editor

Source Link
Interactive
  • 1k
  • 3
  • 16
  • 36

WordPress save values from foreach loop in wp_editor

I have created a custom metabox that contains a wp_editor. The wp_editor shows content of a uploaded .csv file and constructs a table. I want to allow the users to edit the table after uploading the .csv file.

This works. Now I want to make it a little bit more advanced.
So I added the possibility to upload multiple .csv files.
This also works. The problem is the saving of the wp_editors.
wp_editor states that every editor should have it's own editor_id.
see: http://codex.wordpress.org/Function_Reference/wp_editor

I can add a number??? to the editor_id but the problem is saving/updating the content.
I do this with a save function.
See below what I did.
This is the foreach loop checking how many .csv files there are and constructs a wp_editor everytime it comes across one:

$value = get_post_meta($post->ID, 'mcu', true);
$get_url = unserialize ($value);
foreach ($get_url as $list) {
        echo '<p style="margin:50px 0 0 0;">';
        echo '<strong>'.$list.'</strong>';
        ob_start();
        jj_readcsv($list,true);
        $link = ob_get_contents();
        ob_end_clean();
        $editor_id = 'my_uploaded_csv';
        
        wp_editor( $link, $editor_id );
        echo '</p>';
    }

Here is a basic save function for the wp_editor. I can't seem to figure out how I can make this have a foreach loop to so I can save/update all the data.

function save_wp_editor_fields(){
    global $post;
    update_post_meta($post->ID, 'my_uploaded_csv', $_POST['my_uploaded_csv']);
}

I hope anyone can assist me with this.

M.