Support Forum
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
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;
} );
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;
} );
btw. can i edit metaboxes codewise which have been crerated by the custom field UI (Meta Box AIO)?
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/
Thank you Long Nguyen 🙂
Great plugin:)))