Viewing 2 reply threads
  • Author
    Posts
    • #7682
      cyclissmo
      Member

      Hey guys, have a little problem here with an add-more field that has me scratching my head.

      I have an add-more field that serializes it’s data. It works normally when I add values to it. When I remove a value, it does not display some of the values on the edit page, even though they exist in the database. When I check the serialized data in the database, I see the correct field data, but I notice that the array keys have gaps, which I presume is confusing the field renderer?

      Here is my field code:

      piklist( 'field', array(
      	'type'			=> 'group',
      	'label' 		=> false,
      	'description'	=> $description,
      	'field' 		=> 'staff_departments',
      	'scope' 		=> 'post_meta',
      	'serialize'		=> true,
      	'add_more' 		=> true,
      	'fields' 		=> array(
      		array(
      			'type' 		=> 'select',
      			'field' 	=> 'term_id',
      			'value' 	=> '',
      			'label' 	=> 'Department',
      			'choices' 	=> array( '' => '' ) + $options,
      		),
      		array(
      			'type'		=> 'text',
      			'field' 	=> 'sort',
      			'label'		=> 'Sort',
      			'value'		=> '',
      		),
      		array(
      			'type' 		=> 'group',
      			'field' 	=> 'roles',
      			'add_more' 	=> true,
      			'fields'	=> array(
      				array(
      					'type' 			=> 'text',
      					'field' 		=> 'role',
      					'label' 		=> false,
      					'value'			=> '',
      				),
      		) )
      	)
      ) );

      Assuming there are four values, and I remove the third one, after saving this is what I see in the database (note the gap in array keys):

      Array
      (
        [0] => Array
          (
            [term_id] => 21
            [sort] => 
            [roles] => Array
              (
                [0] => Array
                  (
                    [role] => 
                  )
      
              )
          )
        [1] => Array
          (
            [term_id] => 23
            [sort] => 
            [roles] => Array
              (
                [0] => Array
                  (
                    [role] => 
                  )
              )
          )
        [3] => Array
          (
            [term_id] => 5
            [sort] => 
            [roles] => Array
              (
                [0] => Array
                  (
                    [role] => 
                  )
              )
          )
      )

      Any ideas what might be causing this weirdness?

    • #7690
      Steve
      Keymaster

      @cyclissmo– Looks like you found a bug. I’ll add it to the list we’re working on, but I’m not sure it will get fixed quickly. We’re still fixing older bugs and writing unit tests.

    • #7691
      cyclissmo
      Member

      Thanks for checking in on it, Steve.

      For now I can just tap into one of the many postmeta filters to re-index the array (assuming that’s what is causing the problem!) I’ll update this post if I discover anything new.

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