Image Select Field only offers first option
- This topic has 2 replies, 1 voice, and was last updated 4 years, 3 months ago by
Beda Schmid.
-
AuthorPosts
-
January 16, 2021 at 7:13 PM #24058
Beda Schmid
ParticipantI added a Image Select Field with a couple options like so:
value:https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/a5d8ffad-19df-3aa9-9e06-870146871026.jpg value: https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/a79b4e0b-a842-300a-a503-8288e4e8603c.jpg
I use AIO, and this is the code it generates:
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' ); function your_prefix_register_meta_boxes( $meta_boxes ) { $prefix = ''; <pre><code>$meta_boxes[] = [ 'title' => esc_html__( 'Usdfagdhntitled Field Group', 'text-domain' ), 'id' => 'usdfagdhntitled-field-group', 'post_types' => ['post'], 'context' => 'normal', 'priority' => 'high', 'fields' => [ [ 'id' => $prefix . 'image_select_8n1slce1j5p', 'type' => 'image_select', 'name' => esc_html__( 'Image Select', 'text-domain' ), 'options' => [ 'value' => esc_html__( 'https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/a79b4e0b-a842-300a-a503-8288e4e8603c.jpg', 'text-domain' ), ], ], ], ]; return $meta_boxes;
}
We can see it adds only one option, and that is also what I see in the Post Edit Screen: just one option.
I tried to store the code in the functionsphp and add the other options manually like so
'options' => [ 'value' => esc_html__( 'https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/a79b4e0b-a842-300a-a503-8288e4e8603c.jpg', 'text-domain' ), 'value' => esc_html__( 'https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/537f927b-2c14-3162-8a44-c0ac6c39fc8f.jpg', 'text-domain' ), ],
But it still offers only one image.
I have tested this with Theme 2021 and no other plugins...
January 16, 2021 at 7:15 PM #24059Beda Schmid
ParticipantThe trick is to increase the array key.
Hence, the correct code is
'options' => [
'value' => esc_html__( 'https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/a79b4e0b-a842-300a-a503-8288e4e8603c.jpg', 'text-domain' ),
'value1' => esc_html__( 'https://the-million-posts--site.tukutoi.com/wp-content/uploads/2020/12/537f927b-2c14-3162-8a44-c0ac6c39fc8f.jpg', 'text-domain' ),
],
],
AIO does not do this, it seems.
Perhaps it is a bug?January 16, 2021 at 7:17 PM #24060Beda Schmid
ParticipantOK, I think I misunderstood the hint in the field
It works, if we indeed alter the value keys in the GUI.
Sorry the trouble, no issue at all here, can be closed...
-
AuthorPosts
- You must be logged in to reply to this topic.