- This topic has 3 replies, 2 voices, and was last updated 1 year, 5 months ago by .
-
Topic
-
The Image Advanced field in the block editor saves only the initial order the images have been added. Changing the order afterwards (by dragging them) does not get saved. When opening the Code Editor mode in the block editor, I can change the order of the IDs which will then get saved. But it is not working from the GUI.
Here is my code:function create_meta_box($meta_boxes) { $meta_boxes[] = array( 'id' => 'twt-gallery-block', 'title' => 'TWT Gallery', 'type' => 'block', 'icon' => 'layout', 'category' => 'layout', 'render_callback' => array($this, 'render_block'), 'supports' => array( 'anchor' => true, 'customClassName' => true, ), 'fields' => array( array( 'name' => 'Images', 'id' => 'images', 'type' => 'image_advanced', ), array( 'name' => 'Row Height (px)', 'placeholder' => '300', 'id' => 'row_height', 'type' => 'number', ), array( 'name' => 'Displayed At Start', 'placeholder' => '20', 'id' => 'displayed_at_start', 'type' => 'number', ), array( 'name' => 'Load More Increments', 'placeholder' => '10', 'id' => 'load_more_increments', 'type' => 'number', ), array( 'name' => 'Last Row', 'id' => 'last_row', 'type' => 'select', 'options' => array( 'justify' => 'justify', 'nojustify' => 'don\'t justify' ) ), ) ); return $meta_boxes; } function render_block($attr, $is_preview = false, $post_id = null) { if ( empty( $attr['data'] ) ) { return; } // Unique HTML ID if available. $id = 'twt-gallery-' . ( $attr['id'] ?? '' ); if ( ! empty( $attr['anchor'] ) ) { $id = $attr['anchor']; } // Custom CSS class name. $class = 'twt-jg-c ' . ( $attr['className'] ?? '' ); if ( ! empty( $attr['align'] ) ) { $class .= " align{$attr['align']}"; } if($is_preview) { ?> " class="" style="background:#eee;min-height:100px;padding:10px"> <strong>TWT Gallery</strong> '.wp_get_attachment_image($attr['data']['images'][0], 'medium'); } ?> <?php } elseif(isset($attr['data']['images'])) { $gallery_attr = array(); if(isset($attr['data']['row_height'])) { $gallery_attr['row_height'] = $attr['data']['row_height']; } if(isset($attr['data']['displayed_at_start'])) { $gallery_attr['limit'] = $attr['data']['displayed_at_start']; } if(isset($attr['data']['load_more_increments'])) { $gallery_attr['increment'] = $attr['data']['load_more_increments']; } if(isset($attr['data']['last_row'])) { $gallery_attr['last_row'] = $attr['data']['last_row']; } $gallery_attr['id'] = $id; $gallery_attr['class'] = $class; echo $this->render_gallery($attr['data']['images'], $gallery_attr, $post_id); } }
Thank you for checking into this.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.