Skip Navigation

[Resolved] Multiple lines field – I would like the output to include paragraph tags

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by julesW 3 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2204277
toolset_paragraph-tags.png

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

#2205659

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

#2206431

Thank you, Waqar.

That was exactly what I needed!