Get post excerpt by post id in WordPress

/**
 * 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 Comment

  1. Tom December 9, 2016 at 12:16 pm #

    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.

Leave a Reply