Custom post meta with new lines
-
I am trying to add (programmatically) a custom meta tag to a post which contains new lines.
Following the advice on https://codex.www.ads-software.com/Function_Reference/update_post_meta#Character_Escaping I tried the following:
<?php $escaped_meta = "field1\\r\\nfield2\\r\\nfield3"; update_post_meta( $id, 'double_escaped_json', wp_slash( $escaped_meta ) ); ?>
This stored the \\r\\n in the database. Removing the double slash in the $escaped_meta variable leads to \r\n being stored literally in the database (so it is being sent as \\r\\n). Removing the wp_slash() leads to rn being stored in the database with no escaping.
Is there a reliable doing this such that the actual data sent to the database is:
UPDATE postmeta SET value='field1\r\nfield2\r\nfield3' WHERE id='$id'
?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom post meta with new lines’ is closed to new replies.