40
loading...
This website collects cookies to deliver better user experience
It's worth noting that the same meta_key can be used several times to record different metadata variants (see the unique flag below). A string, integer, or array can be used as the meta_value. If the value is an array, it will be serialized automatically before being put in the database.
The function receives a post_id, a meta_key, a meta_value, and a unique flag, same as add_post_meta().
{"key":"value with \"escaped quotes\""}:
$escaped_json = '{"key":"value with \"escaped quotes\""}';
update_post_meta( $id, 'escaped_json', $escaped_json );
$broken = get_post_meta( $id, 'escaped_json', true );
/*
$broken, after stripslashes(), ends up unparsable:
{"key":"value with "escaped quotes""}
*/
$escaped_json = '{"key":"value with \"escaped quotes\""}';
update_post_meta( $id, 'double_escaped_json', wp_slash( $escaped_json ) );
$fixed = get_post_meta( $id, 'double_escaped_json', true );
/*
$fixed, after stripslashes(), ends up as desired:
{"key":"value with \"escaped quotes\""}
*/
add_post_meta( 68, '_color', 'red', true );