Hi. I'm trying to create a custom meta box on Wordpress with multiple text fields.

The idea is that there is initially one text box, then you can click the button 'Add New' and a another text box is added. This needs to be via Ajax; using Javascript doesn't physically create the HTML and I have to use a PHP foreach loop to get all of the values from and combine them into an array in order to be saved.

Currently via PHP I've created a foreach loop that creates a text box for each value from the custom field (etc, 3 text boxes). I want to create a button that when clicked, it will add another blank text box as part of this foreach loop. When the post is saved, it will get the values from the 4 text boxes and save them back into the array.

Is this possible? Pulling my hair out over this!


You could try to install a working example of add_meta_box (eg. this one), then set about modifying it to your own specification.

I don't pretend to understand everything in the example, but it would appear that downstream client-side and server-side handling is managed automatically.