Clarkson-Core icon indicating copy to clipboard operation
Clarkson-Core copied to clipboard

Research avoiding overruling the global $post in get_exerpt

Open rianrietveld opened this issue 7 years ago • 3 comments

Research other way to retrieve the excerpt without overruling the global $post in Clarkson_Object.php in the function get_excerpt. See also https://developer.wordpress.org/reference/functions/get_the_excerpt/#comment-2457

rianrietveld avatar Jun 26 '18 15:06 rianrietveld

Looking at the code, maybe we should just copy the code from WP? We didn't want to do the at first, because we would have to monitor the inner workings of this WP function and sync it when it has changes.

This may be the only code needed, but it should be thoroughly tested, because previous versions of this function broke a bunch of sites.

    $post = $this->_post->post_excerpt;
    if ( post_password_required( $post ) ) {
        return __( 'There is no excerpt because this is a protected post.' );
    }
    return apply_filters( 'the_excerpt', $post, $post );
    // should we also apply get_the_excerpt filter?

It may even have happend that we tried the above code, but we ask @MarcZijderveld or @NielsdeBlaauw if they did so.

jmslbam avatar Jun 27 '18 08:06 jmslbam

@jmslbam The problem with the copy is that when $this->_post->post_excerpt is empty or null, WordPress takes the post_content of the current global $post. This is fine in the while(have_posts()) loop, but does not work for our use case. We want to have the excerpt of a post we specify, instead of the global one (or hope the post_excerpt is not empty).

NielsdeBlaauw avatar Jun 28 '18 07:06 NielsdeBlaauw

This was originally added because of https://github.com/level-level/Clarkson-Core/issues/89

NielsdeBlaauw avatar Sep 10 '19 14:09 NielsdeBlaauw