Storing JSON data as WordPress User Metadata

update_user_meta() (and, by extension, Advanced Custom Fields update_field() function) messes up UTF-8 encoding because it strips slashes from entered data.

Get around this by using wp_slash on your encoded JSON string

update_user_meta( $user_id, 'my_json_field', wp_slash( $json_string ) );

Or if you’re using the Advanced Custom Fields plugin and prefer that syntax:

update_field( 'my_json_field', wp_slash( $json_string ), 'user_' . $user_id );

Leave a Reply

Your email address will not be published. Required fields are marked *