My example custom content type is for recipes. There will be a meta-box for ingredients. In this meta-box there will be three attributes and a "add" button.


Add Button

My question: If There are multiple ingredients but one meta-box how can I have the user add each ingredient click a button "add" and when they are done adding and when they publish the post that full list of ingredients is saved?

Would they use Ajax or something to enter the attributes values click "add" and that entry is added to some sort of static view array and the fields are blank again so they can add another.

  • Append your additional fields from script when 'Add' is clicked. When post is submitted, save all field values at once. This could be one approach. Commented Aug 22, 2014 at 7:02
  • Using wpse as a cookbook (tee hee) see Add X meta box inputs based on form at top of meta box, how to do it right? in the related column...
    – bonger
    Commented Aug 22, 2014 at 7:51
  • I guess I should have also asked if this type of functionality is already part of the core system. Really it seems like I just need to get the value of each field when "Add" is clicked and using AJAX store it in a dynamic array as well as show the current list of values in a <UL>. This array will continue to grow until they publish their post and the whole array will be added to the database. I am sure there is an easier way to do this.
    – Denoteone
    Commented Aug 22, 2014 at 8:09
  • No it's not part of core. No there isn't an easier way of doing it apart from using the various systems (eg WPAlchemy) or plugins that feature repeating fields.
    – bonger
    Commented Aug 22, 2014 at 13:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.