"Special Field Type" to group fields?
- This topic has 5 replies, 2 voices, and was last updated 6 years, 9 months ago by
Anh Tran.
-
AuthorPosts
-
July 24, 2018 at 1:08 AM #10674
nfyp145
ParticipantHi Tran
If possible, I'd like to request a field to group other fields.
Similar to "Fieldset Text" - not only for "Text", but also for all other fields.
array( 'id' => 'my_content', 'name' => 'My Content', 'type' => 'fieldset_for_all_field_types', 'fields' => array( array( 'id' => 'title', 'name' => 'Title', 'type' => 'text', ), array( 'id' => 'subtitle', 'name' => 'Subtitle', 'type' => 'textarea', ), array( 'id' => 'image', 'name' => 'Image', 'type' => 'image', ), array( 'id' => 'content', 'name' => 'Content', 'type' => 'wysiwyg', ), ), ),
There is a framework (Codestar Framework) supporting such field type - Codestar Framework - Fieldset
Thanks much and looking forward to hearing back your opinion.
July 24, 2018 at 11:44 AM #10681Anh Tran
KeymasterHi,
Have you tried MB Group? It's the
group
field type, and supports all kind of sub-fields, including sub-groups. And it's cloneable (repeatable).July 24, 2018 at 12:24 PM #10684nfyp145
ParticipantOf course, I'm using "MB Group" to group different fields. It works well so far.
array( 'id' => 'my_content', 'collapsible' => true, 'group_title' => 'My Content', 'type' => 'group', 'fields' => array( array( 'id' => 'title', 'name' => 'Title', 'type' => 'text', ), array( 'id' => 'subtitle', 'name' => 'Subtitle', 'type' => 'textarea', ), array( 'id' => 'image', 'name' => 'Image', 'type' => 'image', ), array( 'id' => 'content', 'name' => 'Content', 'type' => 'wysiwyg', ), ), ),
But I'd like to use "MB Group" for specific tasks - such like collapsible, cloneable, sortable...
Could it be nice having a field type (only) for grouping different custom fields? That way, it'll help reducing server load.
Thanks again Tran!
July 24, 2018 at 2:18 PM #10686Anh Tran
KeymasterDo you mean just grouping fields via UI? A kind of putting them in a wrapper div, but no touch on the data and each of fields still can store value as normal?
July 24, 2018 at 3:08 PM #10689nfyp145
ParticipantHi Tran...
Not grouping fields via UI.
Grouping fields (each field) under one special field. Under one roof.
- main_id * text_field_id * image_field_id * slider_field_id * time_field_id ...
That way, it'd a lot easier when naming all IDs.
And also, the dev just needs to focus on (main_id) when getting value.For example,
/* Post Meta Box */ add_filter('rwmb_meta_boxes', 'set_post_meta_box'); function set_post_meta_box($meta_boxes) { $meta_boxes[] = array( 'id' => 'post_meta_box', 'post_types' => 'post', 'tab_style' => 'left', 'tabs' => array( 'box_1_tab' => 'Box 1', 'box_2_tab' => 'Box 2', ), 'title' => 'Post Meta Box', 'fields' => array( /* Box 1 */ array( 'id' => 'box_1', 'tab' => 'box_1_tab', 'type' => 'special_fieldset', 'fields' => array( array( 'id' => 'title', 'name' => 'Title', 'type' => 'text', ), array( 'id' => 'description', 'name' => 'Description', 'type' => 'textarea', ), ), ), /* Box 2 */ array( 'id' => 'box_2', 'tab' => 'box_2_tab', 'type' => 'special_fieldset', 'fields' => array( array( 'id' => 'title', // Same ID from Box 1 'name' => 'Title', 'type' => 'text', ), array( 'id' => 'description', // Same ID from Box 1 'name' => 'Description', 'type' => 'textarea', ), ), ), ), ); return $meta_boxes; }
To return values...
$box_1 = rwmb_meta('box_1'); $box_1_title = $box_1['title']; $box_1_description = $box_1['description']; $box_2 = rwmb_meta('box_2'); $box_2_title = $box_2['title']; $box_2_description = $box_2['description'];
Without defining long ID names for each field,
the dev can return values for Title and Description just usingbox_1
andbox_2
IDs.July 25, 2018 at 5:32 PM #10713Anh Tran
KeymasterI got it. So your main purpose is not writing different IDs for groups.
While this is not recommended, but I think it still works with the current version of Groups. I mean you can set the same ID for sub-fields in different groups. And then you can access to them using the same keys. It should work in most cases. Please just test it.
-
AuthorPosts
- You must be logged in to reply to this topic.