Date, media and repeater sections

Support MB Custom Table Date, media and repeater sectionsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32141
    Torsten GaugerTorsten Gauger
    Participant

    Hello,

    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:

      1. 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?
      1. 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)
      1. 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;
    }
    #32160
    Long NguyenLong Nguyen
    Moderator

    Hi,

    1. 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
    2. 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/
    3.             array(
                      'id'   => 'story_basic_repeater_paragraph_text',
                      'type' => 'text',
                      'name' => 'Story Basic Repeater Paragraph Text',
                      'clone' => true,
                  ),
    4. 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
    #32183
    Torsten GaugerTorsten Gauger
    Participant

    Thank you for your detailed answer 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.