[ create a new paste ] login | about

Link: http://codepad.org/WhnTyOZa    [ raw code | output | fork | 3 comments ]

PHP, pasted on Oct 19:
<?php

    $meta_box = array
    (
        'id' => 'my-meta-box',
        'title' => 'Custom Input Fields',
        'page' => 'page',
        'context' => 'normal',
        'priority' => 'high',
        'fields' => array ()
    );
    
    
    $dynamicNumber = 2;
    $idPrefix = 'textarea';
    assert('$dynamicNumber > 0');
    $dynamicIds = range(1, $dynamicNumber);
    
    $fields = &$meta_box['fields'];
    foreach($dynamicIds as $id)
    {
        $fields[] = array( //this array must be created dynamic 
                          'name' => 'Textarea',
                          'desc' => 'Enter big text here',
                          'id' => sprintf('%s%d', $idPrefix,$id), //id is textarea + number
                          'type' => 'textarea',
                          'std' => 'Default value'
                      );
    }
    unset($fields);

print_r($meta_box);


Output:
Array
(
    [id] => my-meta-box
    [title] => Custom Input Fields
    [page] => page
    [context] => normal
    [priority] => high
    [fields] => Array
        (
            [0] => Array
                (
                    [name] => Textarea
                    [desc] => Enter big text here
                    [id] => textarea1
                    [type] => textarea
                    [std] => Default value
                )

            [1] => Array
                (
                    [name] => Textarea
                    [desc] => Enter big text here
                    [id] => textarea2
                    [type] => textarea
                    [std] => Default value
                )

        )

)


Create a new paste based on this one


Comments:
posted by krutarth941 on May 5
this is a test comment
reply
posted by krutarth941 on May 5
krutarth941
reply
posted by krutarth941 on May 5
test1
reply