Title: Help! Serialized data.
Last modified: August 21, 2016

---

# Help! Serialized data.

 *  [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/help-serialized-data/)
 * Hi,
    When saving post data, there are cases where MF sends arrays even if only
   one value is allowed (like a dropdown menu with only one `option` allowed). The
   result is the data is saved as a serialized array containing one item (WordPress
   serializes passed arrays). This makes custom queries uselessly complicated and
   breaks functionnalities for plugins which doesn’t handle serialized data.
 * I successfully modified `mf_post.php` to save the value of a specific field as
   string, but it would be more efficient to filter out fields by `type`.
    However
   I’m only able to use the `$field_name` variable, I can’t get the `$field_type`
   variable.
 * I wonder what happened with the function `mf_process_value_by_type($field_name,
   $value)` in `mf_post.php` -> `mf_save_post_data( $post_id )`.
    It seems it never
   got implemented.
 * If a developer could chime in, please.
    Any help would be greatly appreciated.
 * Fabrice
 * [http://wordpress.org/plugins/magic-fields-2/](http://wordpress.org/plugins/magic-fields-2/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/help-serialized-data/#post-4236092)
 * Well that was rather simple actually.
    The modifications bellow allows for writing
   and reading string data in place of serialized array if the array contains only
   one child (`dropdown`)
 * mf_post.php, line 278:
 *     ```
       // Adding field value meta data
       add_post_meta($post_id, "{$field_name}", $value);
       ```
   
 * becomes:
 *     ```
       // Adding field value meta data
       if(is_array($value) && count($value) == 1){
         add_post_meta($post_id, "{$field_name}", implode('',$value));
       }else{
         add_post_meta($post_id, "{$field_name}", $value);
       }
       ```
   
 * mf_front_end.php, line 481:
 *     ```
       case 'dropdown':
         $result = ($options['multiple'])? $value[0] : $value ;
         break;
       ```
   
 * becomes:
 *     ```
       case 'dropdown':
       $result = ($options['multiple'] == '0' && is_array($value))? $value[0] : $value ;
       break;
       ```
   
 * This doesn’t break previously entered data and update new/modified to the new
   format.
 * Fabrice

Viewing 1 replies (of 1 total)

The topic ‘Help! Serialized data.’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/magic-fields-2.svg)
 * [Magic Fields 2](https://wordpress.org/plugins/magic-fields-2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/magic-fields-2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/magic-fields-2/)
 * [Active Topics](https://wordpress.org/support/plugin/magic-fields-2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/magic-fields-2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/magic-fields-2/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/help-serialized-data/#post-4236092)
 * Status: not resolved