Max Clone per post
- This topic has 5 replies, 2 voices, and was last updated 4 years, 6 months ago by
julian.
-
AuthorPosts
-
April 22, 2021 at 2:04 AM #27473
julian
ParticipantHi,
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.
thanksApril 22, 2021 at 3:42 PM #27503Long Nguyen
ModeratorHi 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; } );April 22, 2021 at 3:55 PM #27505julian
Participanthi 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; } );April 22, 2021 at 4:19 PM #27508julian
Participantbtw. can i edit metaboxes codewise which have been crerated by the custom field UI (Meta Box AIO)?
April 23, 2021 at 6:22 AM #27543Long Nguyen
ModeratorHi,
It is possible. You can follow this article to know how to customize an existing meta box https://docs.metabox.io/edit-meta-boxes/
April 26, 2021 at 5:36 PM #27655julian
ParticipantThank you Long Nguyen 🙂
Great plugin:)))
-
AuthorPosts
- You must be logged in to reply to this topic.