Looking at your site, the problem seems to be a little different.
For every post, the excerpt of the first post is shown. And not just once, but three times. This happens only on the website, but not the RSS feed or the REST API.
Since the code you provided looks fine, it seems that something on your site is messing with the excerpt in some other way. This can be a plugin or something in your theme mixing up the global $post
object or hooking into the the_excerpt
or get_the_excerpt
filters.
To debug this, you should first disable all your plugins to see if the bug persists.
After that, you can hook into get_the_excerpt
to see whether the post object has been modified by using good ol’ var_dump()
(or just use Xdebug):
add_filter( 'get_the_excerpt', function( $excerpt, $post ) {
var_dump( $excerpt, $post );
return $excerpt;
}, 10, 2 );
If the output doesn’t look right, see which other functions hook into this filter by using something like this:
global $wp_filter;
print_r( $wp_filter['get_the_excerpt'] );
If everything looks alright, check the the_excerpt
filter as well:
add_filter( 'the_excerpt', function( $excerpt ) {
var_dump( $excerpt, get_post() );
return $excerpt;
} );
global $wp_filter;
print_r( $wp_filter['the_excerpt'] );