In my custom post-type, I am building a multidimensional array meta-box with multiple input
s, with below code:
<?php
$services = get_post_meta($post->ID, 'services', true);
foreach ((array) $services as $service) {
echo '<div class="inside">
<div>
<label>Title</label>
<input type="text" name="service[][title]" value="' . $service['title'] . '">
</div>
<div>
<label>Type</label>
<input type="text" name="service[][type]" value="' . $service['type'] . '">
</div>
<div>
<label>Content</label>
<textarea name="service[][text]">' . $service['text'] . '</textarea>
</div>';
}
exit;
?>
It is throwing the Warning:
Illegal string offset 'title' and same warning for
'type'
&'text'
.
I have tried double-quotes as well also.
Using the below code to store the data, if it helps:
function service_save_meta_box_data($post_id) {
// store custom fields values
if (isset($_REQUEST['services'])) {
update_post_meta($post_id, 'services', sanitize_text_field($_POST['service']));
}
}
add_action('save_post_service', 'service_save_meta_box_data');