WP GET THE EXCERPT BY ID

<?php /** * GET THE EXCERPT BY ID *********************************************************************** */ function get_excerpt_by_id($post_id, $length){ $the_post = get_post($post_id); //Gets post ID $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt $excerpt_length = $length; //Sets excerpt length by word count $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images $words = explode(' ', $the_excerpt, $excerpt_length + 1); if(count($words) > $excerpt_length) : array_pop($words); array_push($words, '... '); $the_excerpt = implode(' ', $words); endif; if ( count($words) > $excerpt_length ) { $the_excerpt = $the_excerpt . '<a href="'. get_permalink( $post_id ) .'" class="more-link">Read More</a>'; } else { $the_excerpt = $the_excerpt; } return $the_excerpt; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.