2

I have a simple list (ul>li) which is manipulated with jQuery UI in a custom meta box.

How would I go about saving the contents of the list during post save?

I already have the save function ready, but how do I get the HTML data into PHP so I can put it in the database with update_post_meta?

The list looks like (with class names etc):

<ul>
    <li>Text 1</li>
    <li>Text 2</li>
    <li>Text 3</li>
</ul>

'Text 1, Text 2, Text 3' would be saved.

  • Difficult to tell without seeing the code. But, what about making a mirror inside a hidden input field, which will handle the data to be saved? – brasofilo Feb 28 '13 at 16:24
  • That's kind of the process I'm trying at the moment, hidden input that keeps track of the items as a comma separated list, didn't know if there was a 'proper' way to do it. – Kayo Feb 28 '13 at 16:26
  • AFAIK, only form data will be submitted... – brasofilo Feb 28 '13 at 16:27
  • 1
    A hidden textarea box did the trick, used javascript to update it every time the list was rearranged. – Kayo Feb 28 '13 at 17:11
  • Please mark the answer below as accepted. – funwhilelost Mar 25 '13 at 23:35
1

This can be done with a hidden input field. Make jQuery reflect the contents of the visible list into the hidden field.

Update the meta data using this field and build the initial list based on its values.

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.