Custom Fields
Re-Envisioned
Support MB Frontend Submission Three selects with categories do not save all

  • Creator
    Topic
  • #32338
    Resolved Steffen Larsen
    Participant

    I have three select boxes with different category-children (child_of as query args) but when i save the fields, not all of them gets saved in DB. What am i doing wrong?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #32346
    Long Nguyen
    Moderator

    Hi Steffen,

    Can you please share the code that creates the custom fields? I will check it on my end.

    #32352
    Steffen Larsen
    Participant
    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'      => __( 'Produkt info', 'your-text-domain' ),
            'id'         => 'produkt-info',
            'post_types' => ['produkt'],
            'fields'     => [
                [
                    'name'           => __( 'Produkttype', 'your-text-domain' ),
                    'id'             => $prefix . 'produkttype',
                    'type'           => 'taxonomy',
                    'taxonomy'       => ['category'],
                    'field_type'     => 'select_advanced',
                    'remove_default' => true,
                    'required'       => true,
                    'query_args'     => [
                        'child_of' => 4,
                    ],
                ],
                [
                    'name'    => __( 'Dage på auktion', 'your-text-domain' ),
                    'id'      => $prefix . 'dage_paa_auktion',
                    'type'    => 'number',
                    'max'     => 21,
                    'append'  => 'Dage',
                    'visible' => [
                        'when'     => [['produkttype', '=', 7]],
                        'relation' => 'or',
                    ],
                ],
                [
                    'name'    => __( 'Startpris', 'your-text-domain' ),
                    'id'      => $prefix . 'startpris',
                    'type'    => 'number',
                    'min'     => 0,
                    'max'     => 100000,
                    'append'  => 'DKK',
                    'visible' => [
                        'when'     => [['produkttype', '=', 7]],
                        'relation' => 'or',
                    ],
                ],
                [
                    'name'    => __( 'Bud step', 'your-text-domain' ),
                    'id'      => $prefix . 'bud_step',
                    'type'    => 'number',
                    'max'     => 500,
                    'visible' => [
                        'when'     => [['produkttype', '=', 7]],
                        'relation' => 'or',
                    ],
                ],
                [
                    'name'    => __( 'Max Pris', 'your-text-domain' ),
                    'id'      => $prefix . 'max_pris',
                    'type'    => 'number',
                    'min'     => 0,
                    'max'     => 100000,
                    'append'  => 'DKK',
                    'visible' => [
                        'when'     => [['produkttype', '=', 5]],
                        'relation' => 'or',
                    ],
                ],
                [
                    'name'    => __( 'Pris', 'your-text-domain' ),
                    'id'      => $prefix . 'pris',
                    'type'    => 'number',
                    'min'     => 0,
                    'max'     => 100000,
                    'visible' => [
                        'when'     => [['produkttype', '=', 6]],
                        'relation' => 'or',
                    ],
                ],
                [
                    'name'     => __( 'Beskrivelse', 'your-text-domain' ),
                    'id'       => $prefix . 'beskrivelse',
                    'type'     => 'textarea',
                    'required' => true,
                ],
                [
                    'name'             => __( 'Billeder', 'your-text-domain' ),
                    'id'               => $prefix . 'billeder',
                    'type'             => 'image_upload',
                    'max_file_uploads' => 4,
                ],
                [
                    'name'           => __( 'Betalingsmidler', 'your-text-domain' ),
                    'id'             => $prefix . 'betalingsmiddel',
                    'type'           => 'taxonomy',
                    'taxonomy'       => ['category'],
                    'field_type'     => 'select_advanced',
                    'remove_default' => true,
                    'multiple'       => true,
                    'required'       => true,
                    'query_args'     => [
                        'child_of' => 36,
                    ],
                ],
                [
                    'name'           => __( 'Forsendelsesmuligheder', 'your-text-domain' ),
                    'id'             => $prefix . 'forsendelsesmulighed',
                    'type'           => 'taxonomy',
                    'taxonomy'       => ['category'],
                    'field_type'     => 'select_advanced',
                    'remove_default' => true,
                    'multiple'       => true,
                    'required'       => true,
                    'query_args'     => [
                        'child_of' => 28,
                    ],
                ],
                [
                    'name'       => __( 'Auktionen er slut', 'your-text-domain' ),
                    'id'         => $prefix . 'auktionen_er_slut',
                    'type'       => 'switch',
                    'style'      => 'rounded',
                    'on_label'   => 'Ja',
                    'off_label'  => 'Nej',
                    'attributes' => [
                        'readonly' => true,
                    ],
                    'visible'    => [
                        'when'     => [['produkttype', '=', 7]],
                        'relation' => 'or',
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    #32353
    Steffen Larsen
    Participant

    "Produkttype", "Betalingsmidler", "Forsendelsesmuligheder" only the last one gets saved.

    #32370
    Long Nguyen
    Moderator

    Hi,

    The field taxonomy sets the post terms, so there will be one field category work. If you want to save data for 3 fields, please use the field type taxonomy_advanced.

    Read more on the documentation
    https://docs.metabox.io/fields/taxonomy/#data
    https://docs.metabox.io/fields/taxonomy-advanced/

    #32382
    Steffen Larsen
    Participant

    Nope it still doesn't save anything but the last. I tried everything in the docs.

    #32409
    Long Nguyen
    Moderator

    Hi,

    Have you tried to use the field type taxonomy_advanced? I do not see any issue with this field type on my site.

    #32415
    Steffen Larsen
    Participant

    Yes i tried it, but i had a fieldgroup with the same names. I deleted them, but maybe it's the problem. Maybe i should start over and test it on a fresh install. But thanks anyway.

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