Tagged: add_more, file upload, image
- This topic has 2 replies, 2 voices, and was last updated 6 years, 8 months ago by
aerlaut.
-
AuthorPosts
-
-
June 8, 2015 at 10:35 pm #3837
aerlautMemberI’m trying to create a metabox group with fields :
member_image : upload photo
position : member position
name : member name
interest1 : interest 1
interest1 : interest 2
interest1 : interest 3and came up with the following Piklist field :
piklist('field', array( 'type' => 'group', 'field' => 'members_list', 'label' => 'Members List', 'columns' => 12, 'add_more' => true, 'fields' => array( array( 'type' => 'file', 'field' => 'member_image', 'label' => 'Foto Upload', 'columns' => 12 ), array( 'type' => 'group', 'field' => 'details', 'attributes' => array( 'class' => 'details' ), 'fields' => array( array( 'type' => 'text', 'field' => 'name', 'label' => 'Full Name', 'columns' => 12 ), array( 'type' => 'select', 'field' => 'position', 'value' => 'member', 'label' => 'Position', 'columns' => 3, 'description' => 'Member Position', 'choices' => array( 'head' => 'Head', 'member' => 'Member' ) ), array( 'type' => 'text', 'field' => 'interest1', 'label' => 'Interest 1', 'columns' => 12 ), array( 'type' => 'text', 'field' => 'interest2', 'label' => 'Interest 2', 'columns' => 12 ), array( 'type' => 'text', 'field' => 'interest3', 'label' => 'Interest 3', 'columns' => 12 ) ) ) ) ));The field displays fine, and I’m able to upload and insert data, as can be seen in the attachment. However, the resulting array structure from
`$members_list = get_post_meta($post->ID, ‘members_list’, true)’
returns an incorrect structure for the field
members_list(array of thedetailsgroup is fine)Array ( [member_image] => Array ( [0] => Array ( [0] => 16 ) [1] => Array ( [0] => undefined [1] => 23 ) [2] => Array ( [0] => undefined [1] => 30 ) )Other than index 0, index 0 of the subsequent indices is
undefined. If the following template part is used to loop through the resultpiklist(get_template_directory() . 'template-show-member', array('data' => $members_list, 'loop' => 'data'));a quick check of index 0 of the
$data['member_image']can be done in thetemplate-show-memberto check whether the image ID is stored in the 0th or the 1st index$pic = $data['member_image'][0] != 'undefined' ? $data['member_image'][0] : $data['member_image'][1]; echo "<img src='" . wp_get_attachment_url($pic) . "' />";Although I’m able to post the correct images using the above fix, I don’t think it’s the way it’s meant to behave. Help?
Cheers,
Agi -
June 9, 2015 at 10:05 am #3838
SteveKeymaster@agi–
[0] => undefinedis a bug with the file upload field. We will address in the next version. Are you able to get around it or do you need help? -
June 9, 2015 at 10:31 am #3839
aerlautMemberI’m able to get around it by using the
arr[0] != undefined ? arr[0] : arr[1]check. Looking forward to the next version 🙂
-
-
AuthorPosts
- You must be logged in to reply to this topic.