0

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.

Name
Measurements
Notes

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. – Nilambar Aug 22 '14 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 Aug 22 '14 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 Aug 22 '14 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 Aug 22 '14 at 13:08

Your Answer

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

Browse other questions tagged or ask your own question.