Instead of using get_posts
, which you would use if you wanted to retrieve multiple posts in a loop, you should use get_post
, which only retrieves one post by an ID. There is also a built-in excerpt so you might want to go with retrieving post_excerpt
.
function get_the_excerpt_id($post_id) {
$find = get_post($post_id);
$excerpt = $find->post_excerpt;
$excerpt = strip_tags($excerpt);
$output = substr($excerpt, 0, 100);
return $output;
}
Related Posts:
- How do I get posts by multiple post ID’s?
- What does setup_postdata ($post ) do?
- Query for custom post type? [closed]
- setup_postdata() does not seem to be working?
- Regenerate Slugs From Title of Posts
- get_posts – get all posts by author id
- Why get_posts are only showing five posts (retrieved by assigning a category to them?
- Exclude Current Post from Recent Posts Loop
- WordPress get_posts by category
- get_post random and order by not working
- Alternative to get_posts() due to multithreading cache crash
- How to get current post ID in quick edit callback
- Extract image from content and set it as the featured image
- get_posts with meta_compare=’LIKE’ not working
- How to restore deleted pages/posts?
- Sort “get_pages” by menu order not ordering
- get posts based on meta value of the author
- date_query not returning some posts in date range
- Get the exact SQL query that get_posts() generated
- How do you get posts by meta_query using the JSON API plugin?
- Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?
- Query posts ordering by title, but ignore ” and special characters
- get_posts inside cron
- get_posts not honoring post_status
- Edit the_content function
- Function to check if author has posted within the last x days
- get_posts returning empty array
- How to change featured content to a different tag in WordPress Twenty Fourteen?
- get_posts only children from certain parents
- Problem with get_posts, tax_query and counting the number of posts
- Remove image from post_content on save_post
- custom post type upcoming post and past post
- get_posts cannot grab from specific category
- Make WordPress size and name images for Retina.js
- get excerpt without images
- Filtering custom post type query
- WordPress function/template tag to get first n words of the content
- Check If posts exist in custom post type category, outside of loop
- Pinterest Integration Using functions.php
- data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}
- Display 4 chronological posts starting with a random post
- How to limit get_posts()?
- Allowing SVG uploads in media uploader without plug-in
- meta_query date and time comparisons
- get_posts from post x(offset=>x) to end
- With get_posts(), how can I put a category as a variable
- What’s the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?
- Serialized array, grab specific posts with meta_key/meta_value[0]->is_featured
- How do I combine these 2 queries
- Unable to get_the_content(); of a post in WordPress via AJAX
- get_posts gives different result than wpdb->get_results
- Increase the page size of the WordPress REST API
- How to generate a list of posts published on current day?
- Trouble using get_post
- Cache Get_posts
- Get latest posts from multiple categories
- get_posts() returns all posts rather than the ones specified with ‘post_author’ =>
- Custom Category widget
- get_posts – check if custom field has content?
- Displaying POST content with HTML tags and all
- Zero posts returned with get_posts() on edit.php, but posts are returned on post.php
- Why does ‘meta_key’ return an empty array in get_pages
- What is best practices to move the following code into a function?
- same get_posts function works diffrently in tag.php and functions.php
- Better way to query posts?
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- Using get_posts, I need to use a combination of OR & AND relations
- Get number of posts in each category since last visit
- Remove Featured Images from Posts Older Than a Certain Date
- Get_posts not returning any posts when used with switch_to_blog
- Regex works in regexr, but not if I filter content [closed]
- get_posts array ‘between’ not behaving
- Add end mark at the end of every article
- How to Retrieve Post ID of another page
- Problem in outputting shortcode
- Problem in shortcode outputting content
- Get images by category
- How To Use get_posts & get_the_post_thumbnail Outside The Loop
- WordPress – List Sub Categories and Sub-Sub Categories, With Posts
- Why WP_Query in functions.php is not working when get_posts works?
- Overwriting a Shortcode
- How to show only 1 post from a specific category on the front-page
- Query for draft or scheduled post
- get_posts() and ‘posts_per_page’ arg
- get_pages not returning any results or error when get_posts works
- Show posts in a list separated by day
- How to use wp_editor(); in functions.php then retrieve content in the template
- Sorting posts by specific order
- Single dash converted to double dash
- Display all Post titles with Category and Tag
- Integrating custom API for post content into Admin interface & Public Website [closed]
- Trying to get this function to show below the content
- Intergrate WP into website
- Latest post on specific category and custom css
- Display post’s description and caption
- get posts based on category and post meta
- How to show only text from post in WordPress
- Install wordpress and replace database (from previous site)
- How to I add count of custom posts listed in a post as a prefix to its title
- Link on post title only if post have content