I have a Repeatable Group with two fields, a date and multiple lines. I would like the multiple lines field to add paragraph tags.
Below is the code I'm using to bring in the "Litter Update" field.
if(is_singular('litters')){
$litter_id = get_the_ID();
$litter_updates_output = '';
$litter_updates = toolset_get_related_posts( $litter_id, 'litter-update', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($litter_updates as $litter_updated){
$date_of_update = get_post_meta($litter_updated->ID, 'wpcf-date-of-update', true);
$formatted_date_of_update = date( 'F j, Y', $date_of_update);
$update_message = get_post_meta($litter_updated->ID, 'wpcf-update-message', true);
$litter_updates_output .= sprintf('<h3>%1$s</h3><div>%2$s</div>', $formatted_date_of_update, $update_message);
}
if($litter_updates_output!==''){
echo sprintf('<div class="et_pb_module et_pb_text et_pb_text_align_left et_pb_bg_layout_light litter-update"><div class="et_pb_text_inner">%1$s</div></div>', $litter_updates_output);
}
if($litter_updates_output ==''){
echo sprintf('<div class="et_pb_module et_pb_text et_pb_text_align_left et_pb_bg_layout_light"><div class="et_pb_text_inner"><p class="text-center">Litter Updates Coming Soon!</p></div></div>');
}
}
Can you help me sort how to include <p> tags to the output where line breaks are added within the input field?
Thank you,
Jules
Hi Jules,
Thank you for contacting us and I'd be happy to assist.
To get the formatted field output, you can replace the "get_post_meta" function with the Toolset Types Fields API function "types_render_field":
https://toolset.com/documentation/customizing-sites-using-php/functions/#textarea
For example, the line:
$update_message = get_post_meta($litter_updated->ID, 'wpcf-update-message', true);
Will need to be replaced with:
$update_message = types_render_field( "update-message", array( 'item' => $litter_updated->ID ) );
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thank you, Waqar.
That was exactly what I needed!