1

I have a submenu page set up and I want to add repeatable fields to it.

The submenu page is to add staff holidays (fields will be Start Date, End Date and a multi select to pick the staff members name). Setting up the first lot of fields is not a problem, however, I want a button that each time I click it, it will another set of the above mentioned fields.

I'm aware there will be some Javascript involved and have googled this a few times, but cannot find what I want.

Can somebody help please?

3
  • 1
    I'd look at Advanced Custom Fields Pro, which includes a repeater field type. It sounds like it'll handle all of that for you.
    – Tim Malone
    May 16 '16 at 19:47
  • Apologies, I meant to mention that I don't want to use ACF as it's a self-contained plugin that I'm building. But yes, ACF would be an ideal solution had this have not been the case.
    – sgspragg
    May 16 '16 at 19:49
  • 2
    Ok, in that case, why not look at how ACF does it and learn from that?
    – Tim Malone
    May 16 '16 at 19:50
4

Try this one http://jsfiddle.net/jaredwilli/tZPg4/4/

and use array so input should be something like this

<input type="text" name="data[1][time][start]">
<input type="text" name="data[1][time][end]">

<input type="text" name="data[2][time][start]">
<input type="text" name="data[2][time][end]">

....

then save data as array

update_post_meta($post_id, 'field_name', $_POST['data']); 
0

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.