[wp-trac] [WordPress Trac] #36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are inside a loop
WordPress Trac
noreply at wordpress.org
Fri Jun 3 21:11:55 UTC 2016
#36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are
inside a loop
-----------------------------+------------------------------
Reporter: magicroundabout | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version: 4.5.2
Severity: normal | Resolution:
Keywords: has-patch | Focuses: template
-----------------------------+------------------------------
Comment (by achbed):
For now, I'm using the following as a half-baked workaround:
{{{#!php
<?php
function filter_get_the_excerpt( $text = '', $post = null ) {
if ( empty( $text ) ) {
if ( ! empty( $post ) ) {
if ( ! ( $post instanceof \WP_Post ) ) {
$post = get_post( $post );
}
$text = $post->post_content;
$text = apply_filters( 'the_content', $text );
$text = str_replace(']]>', ']]>', $text);
/**
* Filters the number of words in an excerpt.
*
* @since 2.7.0
*
* @param int $number The number of words. Default
55.
*/
$excerpt_length = apply_filters( 'excerpt_length',
55 );
/**
* Filters the string in the "more" link displayed
after a trimmed excerpt.
*
* @since 2.9.0
*
* @param string $more_string The string shown
within the more link.
*/
$excerpt_more = apply_filters( 'excerpt_more', ' '
. '[…]' );
$text = wp_trim_words( $text, $excerpt_length,
$excerpt_more );
}
}
return $text;
}
add_filter('get_the_excerpt','filter_get_the_excerpt', 1, 2);
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36934#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list