Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i need help with wordpress custom fields currently i store date in one custom field called audio using the "," and "$" example: name, link $ name, link $ etc i have managed to use the data and split the data using php in my theme i.e the playlist. i just need help in creating a custom metabox with 2 text fields that can be duplicated by clicking on adding more and two more fields would show. i only want to use only one custom field to store the data.

thanks

share|improve this question
    
I don't understand this question at all. Why are you storing the date in a field called audio? Why not use multiple custom fields instead of trying to implement your own serialisation? What 2 fields do you want to show when you click on a button? –  anu May 23 '11 at 10:32
add comment

1 Answer

You can store an array in a custom field; WordPress serializes it for you on save and unserializes it on get.

Name your fields with a pseudo array syntax:

<input name="mycustomfield[audio]">
<input name="mycustomfield[date]">

You’ll get a $_POST array:

mycustomfield = array ( 'audio' => 'somevalue', 'date' => 'somedate' )

Now you can do whatever you want with it.

Drawback: Meta queries against serialized arrays are hard. Multiple post meta field are much easier to handle.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.