Documentation: add_more

By adding the “add_more” attribute to any field, you can turn it into an add-more. Hover over the dropdown to see Add-More in action.

 

BASIC ADD-MORE

 

Field Description

 

Code:

<?php
  piklist('field', array(
    'type' => 'text'
    ,'field' => 'text_small_add_more'
    ,'add_more' => true
    ,'label' => __('Text')
    ,'description' => __('Hover to add another field')
  ));

?>

Display

To display the results of the Add-More in your theme, you need to pull the field data and loop through the results, like this:

<?php
 $tests = get_post_meta($post->ID, 'text_small_add_more', false);
  echo '<ul>';
  foreach ($tests as $test):
    echo '<li>' . $test . '</li>';
  endforeach;
  echo '</ul>';
?>

 

ADVANCED ADD-MORE (GROUP Field)

Code:

<?php
piklist('field', array(
  'type' => 'group'
  ,'field' => 'order_add_more'
  ,'add_more' => true
  ,'label' => 'Place Your Order'
  ,'fields' => array(
    array(
      'type' => 'text'
      ,'field' => 'Item'
      ,'columns' => 6
    )
   ,array(
      'type' => 'number'
      ,'field' => 'qty'
      ,'columns' => 1
   )
   ,array(
      'type' => 'datepicker'
      ,'field' => 'due'
      ,'columns' => 2
      ,'options' => array(
        'dateFormat' => 'M d, yy'
      )
   )
  )
));
?>

Display

When using a GROUP Add-More field, you need to pull the field data and loop through the results, similarly as the Basic (non-Group) add-more field. However, you have to add which field in the group you want to display (i.e. $order['item'])

<?php
 $orders = get_post_meta($post->ID, 'order_add_more', false);
  echo '<ul>';
  foreach ($orders as $order):
    echo '<li>' . $order['item'] . ', ' . $order['qty'] . ', ' . $order['due']</li>';
  endforeach;
  echo '</ul>';
?>