Skip Navigation

[Cerrado] [wpv-post-excerpt] works incorrectly

This support ticket is created hace 9 años, 11 meses. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 5 respuestas, has 2 mensajes.

Last updated by Caridad hace 9 años, 11 meses.

Assisted by: Caridad.


Imagine you have set your excerpt length in your themes function.php, like this:

function my_custom_excerpt_length($length)
	return 25;
add_filter( 'excerpt_length', 'my_custom_excerpt_length', 999 );

According to the codex, the excerpt length is defined as "the number of words you wish to display in the excerpt:"

[wpv-post-excerpt] on the other hands, will treat this as the amount of characters to display. So the excerpt generated will be much much smaller.

I'm not sure why you have implemented your own excerpt generator, here's a drop-in replacement for your shortcode that works (although I haven't checked all edge cases):

function shortcode_get_the_excerpt($atts)
	return get_the_excerpt();
add_shortcode( 'wpv-post-excerpt', 'shortcode_get_the_excerpt' );

Regardless, your shortcode should interpret excerpt_length as words and not characters. 25 words or 25 characters can make a big difference in length...


You can disregard the previous version of my shortcode, as it did not work in all cases.

Here is the improved version:

function shortcode_get_the_excerpt($atts)
	extract(shortcode_atts(array('id' => null), $atts));

	$trim_length = apply_filters('excerpt_length', 55);

	if($id !== null)
		$post = get_post(intval($id));
		return $post->post_excerpt !== '' ? $post->post_excerpt : wp_trim_words( $post->post_content, $trim_length);
		return __('ERROR: Invalid post ID given');
add_shortcode( 'get-the-excerpt', 'shortcode_get_the_excerpt' );

Usage in Content Template or View:

[get-the-excerpt id="[wpv-post-id]"]

Any workaround available so I don't have to pass [wpv-post-id] as an argument to the shortcode? (Is there a global variable that can be used instead?)


Dear Stanislav,

You can use advanced excerpts by creating your own shortcode. Add these lines to functions.php in your theme and you can use the [advanced-shortcode] in your View Templates:

add_shortcode('advanced-excerpt', 'my_advanced_excerpt');
function my_advanced_excerpt() {
   return the_advanced_excerpt(get_the_excerpt(), true);

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.




The problem is that Views incorrectly uses the excerpt_length filter in the [wpv-post-excerpt] shortcode.

excerpt_length is the amount of words the excerpt should be.

excerpt_length = 4

Here is an excerpt...


Do you see the difference? The first example is 4 WORDS, the second is 4 CHARACTERS.

If we look inside wpv_shortcode_wpv_post_excerpt() function of Views:

$excerpt_length = apply_filters('excerpt_length', 252);
$excerpt = wp_html_excerpt($excerpt, $excerpt_length)...

But wp_html_excerpt takes amount of -characters- as second parameter, not words.

Instead of wp_html_excerpt, you should use wp_trim_words() so that your function is consistent with get_the_excerpt();
Or at least stop using the excerpt_length filter, because it makes it impossible to use the [wpv-post-excerpt] shortcode...

Does that make sense?


Dear Stanislav,

Let me ask the developers about this and I will get back to you when I have more information.



Dear Stanislav,

We are reviewing it and we will change it on the next version of Views. Keep an eye on the changelog to see what the change will be.

Thank you for bringing this up.


El debate ‘[Cerrado]

Imagine you have set your excerpt length in your themes function.php, like this: function my_custom_excerpt_length($length) { return 25; } add_filter( 'excerpt_length', 'my_custom_excerpt_length', 999 ); According to the codex, the

works incorrectly’ está cerrado y no admite más respuestas.