Upgrade to 5.10.4 breaks subgroups
- This topic has 6 replies, 2 voices, and was last updated 4 months ago by
Topher DeRosia.
-
AuthorPosts
-
December 9, 2024 at 3:24 AM #47131
Topher DeRosia
ParticipantHere's my code: https://gist.github.com/topher1kenobe/4ede89488143bbd78168f15c8528e2ac
I'm using composer to include meta-box in my plugin and it has 5.9.7. When I upgrade to 5.10.4 the UI breaks entirely.
December 10, 2024 at 9:12 AM #47144Peter
ModeratorHello Topher,
Can you please also share the code that creates the field group? Or export the field group to a JSON file and share it here. I will import it to my demo site and use your code to output the subfield value to see how it displays in the frontend.
Following the documentation https://docs.metabox.io/extensions/meta-box-builder/#export--importDecember 10, 2024 at 9:24 AM #47145Topher DeRosia
ParticipantSee if this works: https://gist.github.com/topher1kenobe/bf5902f0698ac53abff605af4cfe3d27
December 10, 2024 at 8:10 PM #47158Peter
ModeratorHello,
I see there are two issues in the code that you create to output the field value:
1. Missing the closing square bracket:
- current:
$image = RWMB_Image_Field::file_info( $image_id, [ 'size' => 'thumbnail' );
- it should be:
$image = RWMB_Image_Field::file_info( $image_id, [ 'size' => 'thumbnail' ] );
2. Missing the field prefix when accessing the subgroup and subfields, for example:
- current:
// Field image: $image_ids = $subgroup[ 'image' ] ?? [];
- it should be:
// Field title: echo $subgroup[ 'ie-slider-title' ] ?? '';
The correct code is:
$groups = rwmb_meta( 'ie-slider-sliders' ); foreach ( $groups as $group ) { // Field slider: $subgroups = $group[ 'ie-slider-slider' ] ?? ''; foreach ( $subgroups as $subgroup ) { // Field title: echo $subgroup[ 'ie-slider-title' ] ?? ''; // Field image: $image_ids = $subgroup[ 'ie-slider-image' ] ?? []; ?> <h3>Uploaded images</h3> <ul> <?php foreach ( $image_ids as $image_id ) : ?> <?php $image = RWMB_Image_Field::file_info( $image_id, [ 'size' => 'thumbnail' ] ); ?> <li><img src="<?php echo $image['url']; ?>"></li> <?php endforeach ?> </ul> <?php // Field caption: echo $subgroup[ 'ie-slider-caption' ] ?? ''; // Field description: $values = $subgroup[ 'ie-slider-description' ] ?? ''; foreach ( $values as $value ) : echo do_shortcode( wpautop( $value ) ); endforeach; } }
December 14, 2024 at 3:22 AM #47177Topher DeRosia
ParticipantBleh, my response wasn't recorded. I think we need to start this thread again. All the code I posted above is from the exporter, which means the flaws are in the exporter as well.
The code I'm actually using is https://gist.github.com/topher1kenobe/ed31a29f40502044e5de87a53d9289b6
And the full plugin is at http://derosia.com/ie-slider.3.0.2.zip
December 15, 2024 at 10:51 PM #47180Topher DeRosia
ParticipantI've found that 5.10.1 does not cause an issue, whilst 5.10.4 does.
December 15, 2024 at 11:33 PM #47181Topher DeRosia
ParticipantOk, it gets weirder. I don't think it's core, I removed meta-box/meta-box-group from my project and it resolved all problems.
-
AuthorPosts
- You must be logged in to reply to this topic.