How I get few words of a Post
-
How can I get the first few words of a post that does not have excerpt?
$args = array( 'posts_per_page' => 5, 'offset' => 0, 'category' => '', 'category_name' => 'Energy', 'orderby' => 'date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'author_name' => '', 'post_status' => 'publish', 'suppress_filters' => true ); $posts_array = get_posts( $args ); foreach($posts_array as $postCategory) { echo get_the_title( $postCategory->ID ); echo get_permalink( $postCategory->ID ); echo get_the_excerpt( $postCategory->ID ); // THIS WITH OU WITHOUT EXCERPT DOES NOT WORK }
The code is printing the title and the permalink but it does not print the first few words of the post.
I would like to understand how to print the first few words of the post, whether or not it has the excerpt delimiter.
Thanks
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘How I get few words of a Post’ is closed to new replies.