/**
* Get post excerpt by post ID.
*
* @return string
*/
function get_post_excerpt_by_id( $post_id ) {
global $post;
$post = get_post( $post_id );
setup_postdata( $post );
$the_excerpt = get_the_excerpt();
wp_reset_postdata();
return $the_excerpt;
}
1 thought on “Get post excerpt by post id in WordPress”
Leave a Comment
You must be logged in to post a comment.

As of WordPress v4.5, the excerpt can simply be obtained by calling
get_the_excerpt( $post_id );. However there is reported bug, see https://core.trac.wordpress.org/ticket/36934.