Custom Fields
Re-Envisioned
Support General Max Clone per post

  • Creator
    Topic
  • #27473
    Resolved julian
    Participant

    Hi,
    how can i limit the number of allowed clones per post in a frontend-form where the max-value is a numeric value from another post meta field which is already existing before the the form is accessable? i tryed to write a function and replaced the value for 'max_clone' in the code with no success.
    thanks

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

    Hi Julian,

    Thank you for reaching out.

    I think you can create a settings page and set the max clone there. Before register, the meta box and custom fields for the post, get the max clone number and assign it to the field.

    In this way, you do not need to remember the post ID to get the field value. For example:

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $settings = get_option('option_name');
        $max_clone = $settings['max_clone_id'];
        $meta_boxes[] = [
            'title' => 'Test Meta Box',
            'fields' => [
                [
                    'type'  => 'text',
                    'id'    => 'name',
                    'name'  => 'Name',
                    'clone' => true,
                    'max_clone' => $max_clone,
                ],
            ],
        ];
        return $meta_boxes;
    } );
    #27505
    julian
    Participant

    hi Long Nguyen,
    thanks for replying. i made it work already. hope that kind of code is clean and secure enough!? what do you think?

    what i dont wrote is that te value for the amount of clones is set by the user aswell in another form before. so the value has to be part of the post too.

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $meta_boxes[] = [
            'title' => 'Test Meta Box',
            'fields' => [
                [
                    'type'  => 'text',
                    'id'    => 'name',
                    'name'  => 'Name',
                    'clone' => true,
                    'max_clone' =>  get_post_meta(htmlspecialchars($_GET['rwmb_frontend_field_post_id']), 'anzahl_tage', true),
                ],
            ],
        ];
        return $meta_boxes;
    } );
    #27508
    julian
    Participant

    btw. can i edit metaboxes codewise which have been crerated by the custom field UI (Meta Box AIO)?

    #27543
    Long Nguyen
    Moderator

    Hi,

    It is possible. You can follow this article to know how to customize an existing meta box https://docs.metabox.io/edit-meta-boxes/

    #27655
    julian
    Participant

    Thank you Long Nguyen 🙂

    Great plugin:)))

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