Date, media and repeater sections
Support › MB Custom Table › Date, media and repeater sectionsResolved
- This topic has 2 replies, 2 voices, and was last updated 3 years, 4 months ago by
Torsten Gauger.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
November 24, 2021 at 8:48 PM #32141
Torsten Gauger
ParticipantHello,
I set up a .php for MB custom Table. The post information is generated using forms in Elementor with e-addons. As beginner, I do not understand all necessary steps. Maybe you have a tip on the following questions:
-
- I have a date field inside my posts. Can you check beneath code if I set it correctly or should I use a different type?
-
- I have repeater fields in my posts. To your recommendation, I tried to only use the subfields and not the whole group. Can you check the below code, if it is correct? (You can see all repeaters bearing the name "repeater" in beneath code)
-
- I do not know how to set the link to a media file (One of the post metas is a video/image) Can you help me find the correct code? (Very bottom of the code)
register_activation_hook( <strong>FILE</strong>, 'prefix_create_table' ); function prefix_create_table() { if ( ! class_exists( 'MB_Custom_Table_API' ) ) { return; } MB_Custom_Table_API::create( 'my_custom_table', array( 'story_basic_category' => 'TEXT NOT NULL', 'story_basic_category_date' => 'VARCHAR(20) NOT NULL', 'story_basic_category_experience' => 'TEXT NOT NULL', 'story_basic_question' => 'TEXT NOT NULL', 'story_basic_category_target_group' => 'TEXT NOT NULL', 'story_basic_repeater_paragraph_heading' => 'TEXT NOT NULL', 'story_basic_repeater_paragraph_text' => 'TEXT NOT NULL', 'story_basic_repeater_paragraph_media' => 'TEXT NOT NULL', ); }
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' ); function your_prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = array( 'title' => 'Meta Box Title', 'storage_type' => 'custom_table', // Important 'table' => 'my_custom_table', // Your custom table name 'fields' => array( array( 'id' => 'story_basic_category', 'type' => 'text', 'name' => 'Story Basic Category', ), array( 'id' => 'story_basic_category_date', 'type' => 'date', 'name' => 'Story Basic Category Date', ), array( 'id' => 'story_basic_category_experience', 'type' => 'text', 'name' => 'Story Basic Category Experience', ), array( 'id' => 'story_basic_question', 'type' => 'text', 'name' => 'Story Basic Question', ), array( 'id' => 'story_basic_category_target_group', 'type' => 'text', 'name' => 'Story Basic Category Target Group', ), array( 'id' => 'story_basic_repeater_paragraph_heading', 'type' => 'text', 'name' => 'Story Basic Repeater Paragraph Heading', ), array( 'id' => 'story_basic_repeater_paragraph_text', 'type' => 'text', 'name' => 'Story Basic Repeater Paragraph Text', ), array( 'id' => 'story_basic_repeater_paragraph_media', 'type' => 'file', 'name' => 'Story Basic Repeater Paragraph Media', ), ), ); return $meta_boxes; }
November 25, 2021 at 4:19 PM #32160Long Nguyen
ModeratorHi,
- To save the default date value in the database, you can use the data type
DATE
, please read more here https://www.mysqltutorial.org/mysql-data-types.aspx - You can add the setting
'clone' => true
to the field that you want to repeat, please read more here https://docs.metabox.io/cloning-fields/ - The media fields (file, image ...) save the ID of the attachment in the database so you can use the helper function to retrieve the attachment URL. Please read more here https://docs.metabox.io/fields/file/#template-usage
array( 'id' => 'story_basic_repeater_paragraph_text', 'type' => 'text', 'name' => 'Story Basic Repeater Paragraph Text', 'clone' => true, ),
November 26, 2021 at 9:42 PM #32183Torsten Gauger
ParticipantThank you for your detailed answer 🙂
-
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.