I tried possible solutions to save \n
as <br />
from my custom post type <textarea>
metabox but it is not working.
I am using a custom made theme and there is no additional plugin installed.
function abhijaan_itinerary_metabox( $post ) {
wp_nonce_field( 'trek_itinerary', 'trek_itinerary_nonce' );
$content = get_post_meta( $post->ID, '_trek_itinerary', true );
$content = preg_replace( '#<br\s*/?>#i', "\n", $content );
?>
<textarea class="trek_inputs required" name="txtItinerary" id="txtItinerary" cols="30" rows="10" placeholder="Itinerary" required><?php echo $content ?></textarea>
<?php
}
function save_custom_metaboxes( $post_id ) {
...
$itinerary = sanitize_text_field( $_POST['txtItinerary'] );
$itinerary = nl2br( $itinerary ); // NOT WORKING!
update_post_meta( $post_id, '_trek_itinerary', $itinerary );
...
}
add_action( 'save_post', 'save_custom_metaboxes' );
Before usinng <textarea>
, I tried WYSIWYG
editor as well. That too had the same issue.
function abhijaan_itinerary_metabox( $post ) {
wp_nonce_field( 'trek_itinerary', 'trek_itinerary_nonce' );
$content = get_post_meta( $post->ID, '_trek_itinerary', true );
wp_editor(
$content,
'txtItinerary',
array( 'media_buttons' => false )
);
}
I am expecting the data to be saved with <br />
in wp_postmeta
table, but it is not happening. I have multiple metaboxes which are using <textarea>
. What is going wrong? :(
UPDATE 1
In fact default post editor (content area) is not saving paragraphs! But if I use other HTML formatting like bullets, they are saved. It is only the <p>
tag which is not saving at all from anywhere!
UPDATE 2
I am using WordPress 5.2.2. Classic Editor
plugin is not installed. However, in my CPT, the default editor is the old one however block editor is coming up when I am writing a normal Post
(not CPT). I am fine with the old editor in my CPT, but don't know why the paragraphs are always ignored!
UPDATE 3 (Screenshots)
UPDATE 4
wpautop( the_content() )
has resolved the content paragraph issue on frontend.