• If I wanted to add more items to an array called $meta_box that was being created in the parents functions.php, how can I accomplish this?
    
    PARENTS FUNCTIONS.PHP
    
    EX. $meta_box = array(
        'id' => 'my-meta-box2',
        'title' => __('Event Information'),
        'page' => 'event',
        'context' => 'normal',
        'priority' => 'high',
        'fields' => array(
    		array(
                'name' => __('Date of Event'),
                'desc' => __('Enter the date of event.'),
                'id' => 'eventdate',
                'type' => 'text',
                'std' => ""
            )
        )
    );
    
    // Add meta box
    function mytheme_add_box2() {
        global $meta_box;
    
        add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box2', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
    }
    
    so in the child theme I want to add 2 more items
    
    $meta_box = array(
        'id' => 'my-meta-box2',
        'title' => __('Event Information'),
        'page' => 'event',
        'context' => 'normal',
        'priority' => 'high',
        'fields' => array(
    		array(
                'name' => __('Date of Event'),
                'desc' => __('Enter the date of event.'),
                'id' => 'eventdate',
                'type' => 'text',
                'std' => ""
            ),
           array(
                'name' => __('Time of Event'),
                'desc' => __('Enter the time(s) of the event.'),
                'id' => 'eventtime',
                'type' => 'textarea',
                'std' => ""
            ),
    		array(
                'name' => __('Google Map Link'),
                'desc' => __('Enter the url for the google map link (leave blank to disable).'),
                'id' => 'eventmaplink',
                'type' => 'text',
                'std' => ""
        )
    );

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could use the array_merge function like this:

    $new_fields = array(
    
           array(
                'name' => __('Time of Event'),
                'desc' => __('Enter the time(s) of the event.'),
                'id' => 'eventtime',
                'type' => 'textarea',
                'std' => ""
            ),
    		array(
                'name' => __('Google Map Link'),
                'desc' => __('Enter the url for the google map link (leave blank to disable).'),
                'id' => 'eventmaplink',
                'type' => 'text',
                'std' => ""
        )
    );
    
    $meta_box['fields'] = array_merge($meta_box['fields'],$new_fields);
    Thread Starter dave9966

    (@dave9966)

    I tried merging but i think there is an ordering issue , because if I merge the 2 arrays in a child functions.php its not registering

    also the above function is being used ei

    add_action(‘admin_menu’, ‘mytheme_add_box2’);

    so maybe there is something i need to do to register these new fields

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to override parent global variable’ is closed to new replies.