Push Metabox field dynamically
enginnk opened this issue · 2 comments
To achive my point I have used below code to set metabox inside post and pages.
Redux_Metaboxes::set_box(
$opt_name,
array(
'id' => 'opt-metaboxes-2',
'post_types' => array( 'page', 'post' ),
'position' => 'side', // normal, advanced, side.
'priority' => 'high', // high, core, default, low.
'sections' => array(
array(
'icon_class' => 'icon-large',
'icon' => 'el-icon-home',
'fields' => array(
array(
'title' => esc_html__( 'Cross Box Required', 'your-textdomain-here' ),
'desc' => esc_html__( 'Required arguments work across metaboxes! Click on Color Field under Metabox Options then adjust this field to see the fields within show or hide.', 'your-textdomain-here' ),
'id' => 'opt-layout',
'type' => 'radio',
'options' => array(
'on' => esc_html__( 'On', 'your-textdomain-here' ),
'off' => esc_html__( 'Off', 'your-textdomain-here' ),
),
'default' => 'on',
),
array(
'id' => 'directory_default_fields',
'type' => 'repeater',
'title' => esc_html__( 'Default fields', 'woffice' ),
'full_width' => false,
'subtitle' => '',
'item_name' => '',
'sortable' => true,
'active' => false,
'collapsible' => false,
'fields' => $fields,
),
),
),
),
)
);
Using foreach loop I have tried to push the repeater field but it's not working.
Loop example ::
$filed_array = array(
array(
'title' => 'Title 1',
'icon' => 'fa fa-check'
),
array(
'title' => 'Title 2',
'icon' => 'fa fa-check'
),
array(
'title' => 'Title 3',
'icon' => 'fa fa-check'
),
array(
'title' => 'Title 4',
'icon' => 'fa fa-check'
),
array(
'title' => 'Title 5',
'icon' => 'fa fa-check'
)
);
$repeater_fields = array();
foreach($filed_array as $key => $repeat_item) {
$field_item = array(
array(
'id' => 'title',
'type' => 'text',
'title' => esc_html__( 'Name', 'domain' ),
'default' => $repeat_item['title'],
),
array(
'id' => 'default',
'type' => 'text',
'title' => esc_html__( 'Default value', 'domain' ),
'default' => '',
),
array(
'id' => 'icon-my-icon',
'type' => 'icon_select',
'title' => esc_html__( 'Legacy Icon Select', 'domain' ),
'default' => $repeat_item['icon'],
// 'options' => redux_icon_select_fa_5_free(),
'enqueue' => true,
'enqueue_frontend' => true,
'stylesheet' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css',
'prefix' => 'fa',
),
);
array_push($repeater_fields,$field_item);
}
Can anyone help me to correct the above result.
In debuglog getting notice.
Is there any specific condition that needs to follow. Tried all possible methods getting same issue.
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'ReduxFramework' does not have a method 'enqueue' in \wp-includes\class-wp-hook.php on line 310
PHP Notice: Undefined index: type in redux-framework\redux-core\inc\extensions\repeater\repeater\class-redux-repeater.php on line 159
PHP Notice: Undefined index: type in redux-framework\redux-core\inc\extensions\repeater\repeater\class-redux-repeater.php on line 159
PHP Notice: Undefined index: type in redux-framework\redux-core\inc\extensions\repeater\repeater\class-redux-repeater.php on line 419
PHP Notice: Undefined index: id in redux-framework\redux-core\inc\extensions\repeater\repeater\class-redux-repeater.php on line 303
PHP Notice: Undefined index: id in Fredux-framework\redux-core\inc\extensions\repeater\repeater\class-redux-repeater.php on line 305
You're doing it wrong. Your array is malformed. I strongly recommend forming your options arrays as suggested on our docs page: devs.redux.io/
If you're going to use these types of methods to create your arrays, you need to have an understanding of PHP past intermediate. We don't have the time or resources to explain or teach basic PHP. If you use Redux, as shown on the docs page, you won't get those errors.