Support Forum
Support › Meta Box Group › BUG: Cloneable group predefines post field
Our field setup:
We have a group filed that is marked as cloneable with a few sub-fields inside the group.
The first sub-field which is constant and shows all the time is а select field with 4 options. Based on the selection we show/hide another post select field ( there are 4 and change based on selected value ).
The bug:
When the initial group is shown everything works as expected, but after you clone it the post field comes with one post automatically selected. If you change the selection in the select field every different field that conditionally shows, comes with a pre-selected post. Even if you leave it as is, the non-selected post fields write in the database in the background.
Here is a short video displaying the behavior : https://imgur.com/a/pIzUD9E
If you need any additional information, let us know
Hello,
Thanks for your feedback.
This issue looks similar to this one https://support.metabox.io/topic/select-advanced-is-not-empty-when-cloned/
and it has been escalated to the development team. I will let you know when I have more information.
I see that this bug was reported 6 months ago, is there no development on it?
This is a very flow breaking issue for us at the moment.
Hello
I had a simlar problem that I tried to solve switching to a clonable group of fields (this is a book catalogue and in some cases I need to add the authors names with pictures, but only to make them visible in the authors' list page).
Following and aexample showed on Mteboax Group page I create this group in $meta_boxes:
[
'name' => esc_html__( 'Autori vari', 'online-generator' ),
'id' => 'extra',
'type' => 'group',
'clone' => true,
'clone_as_multiple' => true,
'sort_clone' => true,
'add_button' => '+ Aggiungi nuovo',
// List of sub-fields.
'fields' => [
[
'type' => 'text',
'name' => esc_html__( 'Nome', 'online-generator' ),
'id' => 'author_name',
],
[
'type' => 'text',
'name' => esc_html__( 'Cognome', 'online-generator' ),
'id' => 'author_surname',
],
[
'type' => 'image',
'name' => esc_html__( 'Foto', 'online-generator' ),
'id' => 'author_pict',
'max_file_uploads' => 1,
],
Then following the query example I added this code in the page template:
<?php
$authors = rwmb_meta( 'extra' );
if ( ! empty( $authors ) ) {
foreach ( $authors as $author ) {
echo '<h4>', 'Auteurs d\'Ouvrages Collectif', '</h4>';
echo '<p>', 'Prénom:', ' ', $author['author_name'], '</p>';
echo '<p>', 'Nom:', ' ', $author['author_surname'], '</p>';
}
}
?>
But the query issue is only blank!
Instead the query to normal fields (not in clonable group) let me show the books' authors in perfect descending surname order.
See the page here
I managed to solve part of the loop query but the associated image in group fields (a single uploaded file) is not still visible in frontend; here the code I used
<?php $extras = rwmb_meta( 'extra' ) ?: []; ?>
<?php $link = get_the_permalink(); ?>
<?php foreach ( $extras as $extra ) {
echo '<div class="card">';
$group = rwmb_meta( 'extra' );
$image_ids = $group['images'] ?? [];
if ( $image_ids ) {
foreach ( $image_ids as $image_id ) {
$image = RWMB_Image_Field::file_info( $image_id, ['size' => 'my-image-size'] );
echo '<img src="' . $image['url'] . '">';
}
}
?>
<?php echo '<h5 class="book-author"><a href="' .$link. '">' .$extra['author_name'] .' ' .$extra['author_surname']. '</a></h5>'; ?>
<?php echo '</div>';
}
?>
But the html output is
without pict