Viewing 2 reply threads
  • Author
    Posts
    • #3837
      aerlaut
      Member

      I’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 3

      and 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 the details group 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 result

      piklist(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 the template-show-member to 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

    • #3838
      Steve
      Keymaster

      @agi– [0] => undefined is 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?

    • #3839
      aerlaut
      Member

      I’m able to get around it by using the arr[0] != undefined ? arr[0] : arr[1] check. Looking forward to the next version 🙂

Viewing 2 reply threads
  • You must be logged in to reply to this topic.