Skip Navigation

[Resolved] I need to insert an excerpt from body field in a view

This support ticket is created 6 years, 1 month 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Shane 6 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1160651

Tell us what you are trying to do? I've created a view with an image from custom image field, the post title and I d'like to inset an excerpt (25 characters) from the body, if I put in view editor this shortcode [wpv-post-body view_template="None"] i see in output the entire body of an article, I need to create from this body an excerpt

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1160736

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Aldo,

Thank you for contacting our support forum.

What you can do is to try this shortcode below.

If it does not work then you can use this custom shortcode that i've created. You can add it to the views custom code by going to Toolset -> Settings -> custom code and click add new.

// Add Shortcode
function wp_trim_post_content( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'id' => '',
			'char' => '',
		),
		$atts
	);

	$post = get_post($atts['id']);
	
	$post_content = $post->post_content;
	
	$excerpt = wp_trim_words($post_content,$atts['char']);
	
	return $excerpt;

}
add_shortcode( 'wp_trim_post_content', 'wp_trim_post_content' );

Then you can use it by just doing this.
[wp_trim_post_content id='[wpv-post-id]' char='25']

Please let me know if this helps.

Thanks,
Shane