Skip to content

Instantly share code, notes, and snippets.

@nirendra
Created November 27, 2013 23:28
Show Gist options
  • Save nirendra/7684889 to your computer and use it in GitHub Desktop.
Save nirendra/7684889 to your computer and use it in GitHub Desktop.
Get excerpt outside the loop based on id
Method 1:
function get_excerpt_outside_loop($post_id) {
$post_excerpt = get_page($post_id) -> post_excerpt;
echo $post_excerpt;
}
Method 2:
function webspec_get_the_excerpt($post_id) {
global $post;
$save_post = $post;
$post = get_post($post_id);
setup_postdata( $post ); // hello
$output = get_the_excerpt();
$post = $save_post;
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment