0

I'm kinda new to WordPress Development and even thought the question seems extremely easy for me, I haven't found any solution that works for me.

My Plugin uses a option to store a simple array of "cost centres", or in other words: array('1222', '1223', 1322', '1455'). You get the idea, just pure numbers.

This array should be editable in the backend. The user should be able to edit/delte/add such cost centres. For now I only focus on "add" since the rest is most likely the same.

I got a pretty simple code to display the cost centres:

    <?php
    //Grab all options
    $options = get_option($this->plugin_name.'cc');
    ?>

    <table id="costcentertable">
        <thead>
            <th>Kostenstelle</th>
        </thead>
        <tbody>
    <?php foreach ($options as $costcenter){ ?>
            <tr>
                <td><?php echo $this->plugin_name.' '.$costcenter ?></td>
            </tr>
    <?php } ?>
        </tbody>
    </table>

    <button id="btnAddd">New</button>

The "new" button got a simple JS attached which appends another field to write into.

Even thought it seems so simple, I have not yet figured out on how to just pass all the values so that I can use a simple "update_options(name,$newValues)". Any clues on how to accomplish that ? I'm happy for all input, since I almost give up...

0

I belive all your numbers are saved as array to your option. So get_option($this->plugin_name.'cc') should give you an array $options.

While adding get this array first, insert a new element to the array $options[] = 'new element' ; . Now save this array to your option again with modified $options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.