Items in group field are out of order
- This topic has 2 replies, 2 voices, and was last updated 2 years, 11 months ago by
alpha.media.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
May 6, 2022 at 2:43 AM #35907
alpha.media
ParticipantWhen using the group field within the block editor, items do not appear in the order they are output to the screen on the front-end. This appears to happen when you have a cloneable group that you can sort.
In my case the order in the block editor does not match the array output on the front-end.
$meta_boxes[] = [ 'title' => 'Highlighted Content', 'id' => 'highlighted-content', 'description' => 'Showcases highlighted content on the homepage in the full-width content module.', 'icon' => 'pressthis', 'category' => 'homepage', 'keywords' => ['highlighted'], 'supports' => [ 'align' => ['full'], ], 'render_template' => get_template_directory() . '/includes/blocks/highlighted-content/block-template.php', 'type' => 'block', 'context' => 'side', 'fields' => [ [ 'name' => 'Section Title', 'id' => 'title', 'type' => 'text', 'label_description' => 'Leave blank if you do not want a title for the section.', ], [ 'name' => 'Background', 'id' => 'background', 'type' => 'select', 'default' => 'is-brand', 'options' => [ 'is-brand' => 'Brand', 'is-light' => 'Light', ], ], [ 'name' => 'Image Size', 'id' => 'image_size', 'type' => 'select', 'options' => [ 'rectangle' => 'Rectangle', 'square' => 'Square', ], 'required' => true, ], [ 'name' => 'Posts', 'id' => 'posts', 'type' => 'group', 'group_title' => '{highlighted_post}', 'clone' => true, 'sort_clone' => true, 'max_clone' => 8, 'fields' => [ [ 'name' => 'Post', 'id' => 'highlighted_post', 'type' => 'post', 'label_description' => 'Select an item to display.', 'post_type' => [ 'post', 'page', 'contests', 'galleries', 'shows', 'videos', 'tribe_events', ], 'field_type' => 'select_advanced', 'query_args' => [ 'number' => 5, ], 'js_options' => [ 'minimumInputLength' => 4, ], ], ], ], ] ];
May 6, 2022 at 10:11 PM #35914Long Nguyen
ModeratorHi,
Can you please share your code that output the field value? I've run your code on my local site and use this code to output the field
post
and the order of the cloneable field display as well on the frontend.$groups = mb_get_block_field( 'posts' ); foreach ( $groups as $group ) { $post_id = $group['highlighted_post']; echo get_the_title( $post_id ); echo "<br>"; }
May 7, 2022 at 12:20 AM #35922alpha.media
ParticipantI figured out the issue. It was on my end. I was grabbing all the post IDs and using the post__in query argument and realized that doesn't order them by the post ID order.
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.