• 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/

Viewing 1 replies (of 1 total)
  • Thread Starter hand_coding

    (@hand_coding)

    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.