-
-
Save jimboobrien/be25c7435c58cac63bb3e4651add3475 to your computer and use it in GitHub Desktop.
Get the excerpt for a WP_Post by post ID.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the excerpt for a WP_Post by post ID. | |
* | |
* @param int $post_id | |
*/ | |
function get_excerpt_by_id( $post_id = 0 ) { | |
global $post; | |
$save_post = $post; | |
$post = get_post( $post_id ); | |
setup_postdata( $post ); | |
$excerpt = get_the_excerpt(); | |
$post = $save_post; | |
wp_reset_postdata( $post ); | |
return $excerpt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment