Having followed this tutorial, I have successfully created a repeatable type custom field. However, I would like to take it to the next stage and have more complex and advanced repeatable fields.
My metabox array is defined like so:
array (
'label' => 'Repeatable',
'desc' => 'A description for the field.',
'id' => 'custom_repeatable',
'type' => 'repeatable'
)
And it is displayed using the following code:
case 'repeatable':
echo '
<a class="repeatable-add button" href="#">+</a>
<ul id="'.$field['id'].'-repeatable" class="custom_repeatable">';
$i = 0;
if ($meta) {
foreach($meta as $row) {
echo '
<li><span class="sort hndle">|||</span>
<input type="text" name="'.$field['id'].'['.$i.']" id="'.$field['id'].'" value="'.$row.'" size="30" />
<a class="repeatable-remove button" href="#">-</a></li>';
$i++;
}
} else {
echo '
<li><span class="sort hndle">|||</span>
<input type="text" name="'.$field['id'].'['.$i.']" id="'.$field['id'].'" value="" size="30" />
<a class="repeatable-remove button" href="#">-</a></li>';
}
echo '</ul>
<span class="description">'.$field['desc'].'</span>';
break;
The first thing I’d like to do is add as second input field, thus saving two independent values.
However, I’m not particular sure on where to start.
Any help would be greatly appreciated.
you can use the latest version of the code for that tutorial.
It is in github:
https://github.com/tammyhart/Reusable-Custom-WordPress-Meta-Boxes
And it’s been updated this week and now repeteables can have multiple fields(text, images, etc…)