Title: Creating a for loop to dynamically populate &#039;fields&#039;
Last modified: August 21, 2016

---

# Creating a for loop to dynamically populate 'fields'

 *  [Sean](https://wordpress.org/support/users/seanhawkridge/)
 * (@seanhawkridge)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/creating-a-for-loop-to-dynamically-populate-fields/)
 * Hello
 * A while ago Steve mentioned (in the context of having repeatable fields) that
   it should be possible to dynamically generate the `fields` array in `slt_cf_register_box()`
   from a `for` loop – to create a given number of meta boxes without having to 
   write them all out. I’ve been trying to do this but failing! Any chance you could
   point me in the right direction?
 * So, for example, if I wanted to generate 15 sets of title/text in a box:
 *     ```
       $fields = array();
       for ($i=0; $i <= 15; $i++) {
       $fields[] =
             array(
                     'name'          => 'title_'.$i,
                     'label'         => 'Title '.$i,
                     'type'          => 'text',
                     'scope'         => array( 'page', 'project', 'except_posts' => array( 4, 45 ) ),
                     'capabilities'  => array( 'edit_posts' )
                 ),
             array(
                     'name'          => 'text_'.$i,
                     'label'         => 'Text '.$i,
                     'type'          => 'textarea',
                     'autop'         => 'true',
                     'scope'         => array( 'page', 'project', 'except_posts' => array( 4, 45 ) ),
                     'capabilities'  => array( 'edit_posts' )
                 )
       };
   
       slt_cf_register_box( array(
           'type'      => 'post',
           'title'     => 'Process Map',
           'id'        => 'process_map',
           'context'   => 'normal',
           'priority'  => 'high',
           'fields'    => $fields
       ));
       ```
   
 * Thanks!
 * [http://wordpress.org/extend/plugins/developers-custom-fields/](http://wordpress.org/extend/plugins/developers-custom-fields/)

The topic ‘Creating a for loop to dynamically populate 'fields'’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/developers-custom-fields.svg)
 * [Developer's Custom Fields](https://wordpress.org/plugins/developers-custom-fields/)
 * [Support Threads](https://wordpress.org/support/plugin/developers-custom-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/developers-custom-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/developers-custom-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/developers-custom-fields/reviews/)

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [meta boxes](https://wordpress.org/support/topic-tag/meta-boxes/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 0 replies
 * 1 participant
 * Last reply from: [Sean](https://wordpress.org/support/users/seanhawkridge/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/creating-a-for-loop-to-dynamically-populate-fields/)
 * Status: not resolved