What is the best data structure for meta boxes?
-
Hi, I have about sixty input fields to be collected with my CPT. For this purpose I’m using the meta boxes. I’d like know if there are data structures suitable to achieve this task. For example, BadgeOS does use of associative arrays of array for defining custom fields. So I’m also trying to define them in my code. Here some snippet codes:
function custom_fields() { $prefix = 'var_'; // First meta box $fields = array ( array ( 'label' => 'Picture', 'id' => $prefix . 'picture', 'desc' => 'Description...', 'type' => 'select', 'options' => array ( 'Picture 1', 'Picture 2', 'Picture 3', ) ), array ( 'label' => 'Something', .... ), ... ); $cutsom_fields[] = array ( 'id' => 'first_meta_box', 'title' => 'Title', 'context' => 'side', 'priority' => 'low', 'page_slug' => 'mf_product', 'fields' => $fields, }; // Second meta box $fields = array ( ... ); $custom_fields[] = array ( ... ), ... // And so forth ... return $custom_fields; } function create_mbox() { $cf = custom_fields(); $cpt = array_column( $cf, 'page_slug' ); foreach ( $cpt as $custom_post ) { foreach ( $cf as $field ) { add_meta_box( $field['id'], 'print_mbox'', $custom_post, $field['context'], $field['priority'], $field['fields'] ); } } }
Is there a more efficient way than this?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘What is the best data structure for meta boxes?’ is closed to new replies.